63 lines
1.8 KiB
Bash
Executable File
63 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Run the bot CLI in the local venv. With no args, drops into the TUI menu.
|
|
# Requires: dev stack up (run scripts/dev.sh up first), .venv with deps.
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Run the bot CLI (app.bot_cli) in the local venv.
|
|
|
|
Usage:
|
|
scripts/bot_cli.sh Drop into the TUI menu.
|
|
scripts/bot_cli.sh <subcommand> [args] One-shot subcommand. Try --help.
|
|
|
|
Examples:
|
|
scripts/bot_cli.sh register
|
|
scripts/bot_cli.sh credit 13c1234 abc12345
|
|
scripts/bot_cli.sh monitor-once --target 5
|
|
|
|
Environment:
|
|
NO_SUDO=1 Skip 'sudo' when checking 'dev.sh status'.
|
|
PYTHON_BIN Override the python interpreter (default: .venv/bin/python).
|
|
EOF
|
|
}
|
|
|
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
|
usage
|
|
exit 0
|
|
fi
|
|
|
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
cd "${ROOT_DIR}"
|
|
|
|
# E2: bail if the dev stack is not running.
|
|
if ! NO_SUDO="${NO_SUDO:-0}" bash scripts/dev.sh status >/dev/null 2>&1; then
|
|
echo "ERROR: dev stack not running. Run 'scripts/dev.sh up' first." >&2
|
|
exit 2
|
|
fi
|
|
|
|
if [[ ! -f .env ]]; then
|
|
echo "ERROR: .env not found. cp envs/dev/.env.example .env (then edit)." >&2
|
|
exit 2
|
|
fi
|
|
|
|
# Load .env into the environment (export everything between 'set -a' and 'set +a').
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
source .env
|
|
set +a
|
|
|
|
# Override DB host/port for the local CLI: docker mysql is published on
|
|
# 127.0.0.1:3306, even though api-server in-network reaches it as mysql:3306.
|
|
export DB_HOST=127.0.0.1
|
|
export DB_PORT=3306
|
|
|
|
PYTHON_BIN="${PYTHON_BIN:-${ROOT_DIR}/.venv/bin/python}"
|
|
if [[ ! -x "${PYTHON_BIN}" ]]; then
|
|
echo "ERROR: ${PYTHON_BIN} not found." >&2
|
|
echo "Create the venv: python3 -m venv .venv && .venv/bin/pip install -r requirements.txt" >&2
|
|
exit 2
|
|
fi
|
|
|
|
exec "${PYTHON_BIN}" -m app.bot_cli "$@"
|