Skip to content

Commit a0bd17d

Browse files
committed
feat(cli): refactor stackctl.sh to use Python wrapper and add bootstrap
Introduce run_py and check_py_cli helpers and centralize all python3 calls through run_py. Add info/warn/die helpers and improved error messages. Add a bootstrap command that: - copies .env.example -> .env when missing - installs tools/requirements.txt into active venv (warn if no venv) - checks Docker presence and Docker Swarm state, with guidance Also keep legacy flag mappings for deploy and ensure help is shown for empty/unknown commands.
1 parent afb37f4 commit a0bd17d

1 file changed

Lines changed: 69 additions & 13 deletions

File tree

stackctl.sh

Lines changed: 69 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,60 @@ IFS=$'\n\t'
99
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
1010
PY_CLI="$SCRIPT_DIR/tools/stackctl_cli.py"
1111

12-
if [[ ! -f "$PY_CLI" ]]; then
13-
printf 'ERROR: Python CLI not found at %s\n' "$PY_CLI" >&2
14-
exit 2
15-
fi
12+
info() { printf "[info] %s\n" "$*"; }
13+
warn() { printf "[warn] %s\n" "$*"; }
14+
die() { printf "[error] %s\n" "$*" >&2; exit 1; }
15+
16+
run_py() {
17+
# run the Python CLI with forwarded args
18+
python3 "$PY_CLI" "$@"
19+
}
20+
21+
check_py_cli() {
22+
if [[ ! -f "$PY_CLI" ]]; then
23+
die "Python CLI not found at $PY_CLI"
24+
fi
25+
}
26+
27+
bootstrap() {
28+
info "Copying .env.example files..."
29+
# Create missing .env files from examples
30+
find . -type f -name '.env.example' -print0 | while IFS= read -r -d '' src; do
31+
dst="${src%.env.example}.env"
32+
if [ ! -e "$dst" ]; then
33+
info "create $dst"
34+
cp "$src" "$dst"
35+
fi
36+
done
37+
38+
if [ -f tools/requirements.txt ]; then
39+
if [ -n "${VIRTUAL_ENV:-}" ]; then
40+
info "Installing Python requirements..."
41+
pip install -r tools/requirements.txt
42+
else
43+
warn "No Python venv active. Activate your venv before running bootstrap for Python deps."
44+
fi
45+
fi
46+
47+
if command -v docker >/dev/null 2>&1; then
48+
info "Docker version: $(docker --version)"
49+
if docker info | grep -q 'Swarm: active'; then
50+
info "Docker Swarm is active."
51+
else
52+
warn "Docker Swarm is not active. Run: docker swarm init"
53+
fi
54+
else
55+
die "Docker not found. Please install Docker Desktop or Docker Engine."
56+
fi
57+
58+
printf "\n[bootstrap] Next steps:\n"
59+
printf " - Review .env files and adjust as needed.\n"
60+
printf " - Run ./stackctl.sh doctor --fix-network\n"
61+
printf " - Run ./stackctl.sh up\n"
62+
printf " - See tools/README.md for CLI usage.\n"
63+
}
64+
65+
check_py_cli
1666

1767
cmd="${1:-}"
1868
shift || true
@@ -35,31 +85,37 @@ case "${cmd:-}" in
3585
*) args+=("$1"); shift ;;
3686
esac
3787
done
38-
exec python3 "$PY_CLI" deploy "${args[@]:-}" ;;
88+
exec run_py deploy "${args[@]:-}" ;;
3989

4090
down)
41-
exec python3 "$PY_CLI" down "$@" ;;
91+
exec run_py down "$@" ;;
4292

4393
status)
44-
exec python3 "$PY_CLI" status "$@" ;;
94+
exec run_py status "$@" ;;
4595

4696
logs)
47-
exec python3 "$PY_CLI" logs "$@" ;;
97+
exec run_py logs "$@" ;;
4898

4999
env)
50-
exec python3 "$PY_CLI" env "$@" ;;
100+
exec run_py env "$@" ;;
51101

52102
doctor)
53-
exec python3 "$PY_CLI" doctor run "$@" ;;
103+
exec run_py doctor run "$@" ;;
104+
105+
--bootstrap|bootstrap)
106+
bootstrap
107+
exit 0 ;;
54108

55109
help|-h|--help)
56-
exec python3 "$PY_CLI" --help ;;
110+
exec run_py --help ;;
57111

58112
"" )
59113
# No command supplied: show help (do not default to deploy)
60-
exec python3 "$PY_CLI" --help ;;
114+
exec run_py --help ;;
115+
61116
*)
62117
printf 'ERROR: unknown command "%s"\n\n' "${cmd:-}" >&2
63-
exec python3 "$PY_CLI" --help ;;
118+
exec run_py --help ;;
64119
esac
65120

121+

0 commit comments

Comments
 (0)