- Remove 312 lines of legacy Bash orchestration fallback in scripts/appctl - Fail closed with exit code 1 and actionable diagnostic error on stderr when socket is absent - Retain fast-path local shell completion handlers (complete, completion) - Auto-detect .venv Python interpreter when PYTHON_BIN is unset - Migrate test_appctl_env_injection_resilience to test production P4 environment assembly - Add unit tests for missing socket and offline completion in test_appctl_cli.py - Mark item completed in todo.txt Closes #9 Refs #9
95 lines
2.9 KiB
Bash
Executable File
95 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# appctl - Unified, Manifest-Driven Container Orchestrator
|
|
# Thin CLI wrapper delegating operational commands to homelab-appctl.service over UDS
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
ENGINE="$SCRIPT_DIR/appctl_engine.py"
|
|
if [ -z "$PYTHON_BIN" ]; then
|
|
if [ -x "$SCRIPT_DIR/../.venv/bin/python3" ]; then
|
|
PYTHON_BIN="$SCRIPT_DIR/../.venv/bin/python3"
|
|
else
|
|
PYTHON_BIN="python3"
|
|
fi
|
|
fi
|
|
SOCKET_PATH="${APPCTL_SOCKET_PATH:-/run/homelab/appctl.sock}"
|
|
CLI_CLIENT="$SCRIPT_DIR/appctl_cli.py"
|
|
|
|
# Fast-path local shell completion helpers
|
|
case "${1:-}" in
|
|
complete)
|
|
exec "$PYTHON_BIN" "$ENGINE" complete "${@:2}"
|
|
;;
|
|
completion)
|
|
cat <<'EOF'
|
|
_appctl_completions() {
|
|
local cur prev words cword
|
|
if declare -F _init_completion >/dev/null 2>&1; then
|
|
_init_completion || return
|
|
else
|
|
COMPREPLY=()
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
words=("${COMP_WORDS[@]}")
|
|
cword=$COMP_CWORD
|
|
fi
|
|
|
|
local commands="list status ssl info up down restart update pull logs config sync health resolve completion"
|
|
|
|
if [ "$cword" -eq 1 ]; then
|
|
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
|
|
return 0
|
|
fi
|
|
|
|
local command="${words[1]}"
|
|
local appctl_cmd="${words[0]}"
|
|
|
|
case "$command" in
|
|
list|status)
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $(compgen -W "--fetch -f --core -c --ssl -s --all -a" -- "$cur") )
|
|
fi
|
|
;;
|
|
ssl)
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $(compgen -W "--core -c --all -a" -- "$cur") )
|
|
else
|
|
local services
|
|
services=$("$appctl_cmd" complete services 2>/dev/null || appctl complete services 2>/dev/null || true)
|
|
COMPREPLY=( $(compgen -W "$services" -- "$cur") )
|
|
fi
|
|
;;
|
|
info)
|
|
if [[ "$cur" == -* ]]; then
|
|
COMPREPLY=( $(compgen -W "--ssl -s" -- "$cur") )
|
|
else
|
|
local services
|
|
services=$("$appctl_cmd" complete services 2>/dev/null || appctl complete services 2>/dev/null || true)
|
|
COMPREPLY=( $(compgen -W "$services" -- "$cur") )
|
|
fi
|
|
;;
|
|
up|down|restart|update|pull|logs|config)
|
|
local services
|
|
services=$("$appctl_cmd" complete services 2>/dev/null || appctl complete services 2>/dev/null || true)
|
|
COMPREPLY=( $(compgen -W "$services" -- "$cur") )
|
|
;;
|
|
completion)
|
|
COMPREPLY=( $(compgen -W "bash" -- "$cur") )
|
|
;;
|
|
esac
|
|
}
|
|
complete -F _appctl_completions appctl
|
|
EOF
|
|
exit 0
|
|
;;
|
|
*)
|
|
if [ ! -S "$SOCKET_PATH" ]; then
|
|
echo "❌ Error: appctl daemon socket not found at $SOCKET_PATH. Ensure homelab-appctl.service is running." >&2
|
|
exit 1
|
|
fi
|
|
exec "$PYTHON_BIN" "$CLI_CLIENT" "$@"
|
|
;;
|
|
esac
|