#!/usr/bin/env bash
# cue — launcher for the Bun-based CLI.
# Resolves its own location so the script works from any cwd and through symlinks.

set -euo pipefail

# Resolve symlinks until we get the real path of this script.
src="${BASH_SOURCE[0]}"
while [ -h "$src" ]; do
  dir="$(cd -P "$(dirname "$src")" && pwd)"
  src="$(readlink "$src")"
  [[ "$src" != /* ]] && src="$dir/$src"
done
CUE_BIN_DIR="$(cd -P "$(dirname "$src")" && pwd)"
CUE_REPO_ROOT="$(cd -P "$CUE_BIN_DIR/.." && pwd)"

export CUE_REPO_ROOT
# Backward compat
export SOUL_REPO_ROOT="$CUE_REPO_ROOT"

if ! command -v bun >/dev/null 2>&1; then
  echo "cue: bun is required but was not found in PATH" >&2
  echo "     install from https://bun.sh and re-run" >&2
  exit 2
fi

exec bun "$CUE_REPO_ROOT/src/index.ts" "$@"
