#!/usr/bin/env bash
# sick — global launcher. Resolves the repo checkout and runs the `sick`
# console script from its venv (fast, offline); falls back to `uv run`
# when the venv is missing, then to `python -m sick.cli`.
set -euo pipefail
SRC="${BASH_SOURCE[0]}"
while [ -L "$SRC" ]; do
  LINK="$(readlink "$SRC")"
  case "$LINK" in /*) SRC="$LINK" ;; *) SRC="$(dirname "$SRC")/$LINK" ;; esac
done
ROOT="$(cd "$(dirname "$SRC")/.." && pwd)"
export SICK_ROOT="$ROOT"
if [ -x "$ROOT/.venv/bin/sick" ]; then
  exec "$ROOT/.venv/bin/sick" "$@"
elif command -v uv >/dev/null 2>&1; then
  exec uv run --project "$ROOT" sick "$@"
else
  exec python3 -m sick.cli "$@"
fi
