#!/usr/bin/env bash
# Launch fire_gimbal_control, resolving the binary relative to this script so it
# works regardless of where the repo is checked out. Extra args are forwarded.
#
#   scripts/run.sh --start
#   scripts/run.sh --mock-serial --mock-camera --no-mqtt --start   # dev, no hardware
set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
bin=""
for cand in "$here/../build/fire_gimbal_control" "$here/fire_gimbal_control" \
            "$here/../fire_gimbal_control"; do
    if [[ -x "$cand" ]]; then bin="$cand"; break; fi
done
if [[ -z "$bin" ]]; then
    echo "fire_gimbal_control binary not found. Build it first:" >&2
    echo "  cmake -B build && cmake --build build" >&2
    exit 1
fi
exec "$bin" "$@"
