#!/bin/sh
# One launcher for the source checkout, standalone CLI bundle, and macOS app.
set -eu
DAYU_LAUNCHER="$0"
while [ -L "$DAYU_LAUNCHER" ]; do
  DAYU_LINK_DIR="$(CDPATH= cd -- "$(dirname -- "$DAYU_LAUNCHER")" && pwd)"
  DAYU_LINK="$(/usr/bin/readlink "$DAYU_LAUNCHER")"
  case "$DAYU_LINK" in
    /*) DAYU_LAUNCHER="$DAYU_LINK" ;;
    *) DAYU_LAUNCHER="$DAYU_LINK_DIR/$DAYU_LINK" ;;
  esac
done
DAYU_CLI_DIR="$(CDPATH= cd -- "$(dirname -- "$DAYU_LAUNCHER")" && pwd)"
DAYU_ROOT="$(CDPATH= cd -- "$DAYU_CLI_DIR/.." && pwd)"
if [ -x "$DAYU_ROOT/engine/dayu-engine" ]; then
  exec "$DAYU_ROOT/engine/dayu-engine" --cli "$@"
fi
if [ -f "$DAYU_ROOT/engine/dayu_engine.py" ] && [ -x "$DAYU_ROOT/.runtime/venv/bin/python" ]; then
  exec "$DAYU_ROOT/.runtime/venv/bin/python" "$DAYU_ROOT/engine/dayu_engine.py" --cli "$@"
fi
printf '%s\n' 'CLI 运行环境缺失。源码项目请先运行 scripts/build_app.sh；分发包请保留 bin/cli 与 engine 的相对位置。' >&2
exit 1
