#!/usr/bin/env bash
set -euo pipefail

repo_root="$(git rev-parse --show-toplevel)"
cd "$repo_root"

if [[ -f "$repo_root/helen/Cargo.toml" ]]; then
  exec cargo run --quiet --manifest-path "$repo_root/helen/Cargo.toml" -- elenchus "$@"
fi

if [[ -f "$repo_root/Cargo.toml" ]] && grep -Eq '^name = "helen"$' "$repo_root/Cargo.toml"; then
  exec cargo run --quiet --manifest-path "$repo_root/Cargo.toml" -- elenchus "$@"
fi

if command -v helen >/dev/null 2>&1; then
  exec helen elenchus "$@"
fi

echo "error: helen binary is not installed or built"
echo "Run elenchus with: helen elenchus \"$*\""
echo "Or build the local binary first: cargo build -p helen"
exit 2
