#!/bin/bash
# MVSEP CLI Test Script

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLI_BIN="$SCRIPT_DIR/target/release/mvsep-cli-test"

if [ ! -f "$CLI_BIN" ]; then
    echo "Error: CLI binary not found. Building..."
    cd "$SCRIPT_DIR"
    cargo build --release
fi

# Check if API token is set
if [ -z "$MVSEP_API_TOKEN" ]; then
    # Try to read from config or environment
    if [ -f "$HOME/.config/mvsep/token" ]; then
        export MVSEP_API_TOKEN=$(cat "$HOME/.config/mvsep/token")
    fi
fi

if [ -z "$MVSEP_API_TOKEN" ]; then
    echo "Error: MVSEP_API_TOKEN environment variable not set"
    echo "Usage: MVSEP_API_TOKEN=your_token $0 <command>"
    exit 1
fi

# Run the CLI
exec "$CLI_BIN" "$@"
