docker-stacks-update: fix --list freeze + unbound variable
- Add missing 'shift' in --list case (caused infinite loop) - Initialize color vars to empty strings before tput block (set -u errored when tput unavailable or non-TTY)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
set -euo pipefail
|
||||
|
||||
# ── Terminal colours ──────────────────────────────────────────────
|
||||
BOLD=""; RED=""; GREEN=""; YELLOW=""; CYAN=""; RESET=""
|
||||
if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then
|
||||
BOLD=$(tput bold 2>/dev/null || true)
|
||||
RED=$(tput setaf 1 2>/dev/null || true)
|
||||
@@ -21,6 +22,7 @@ fi
|
||||
|
||||
# ── State ───────────────────────────────────────────────────────────
|
||||
TARGET_STACKS=() # user-specified stacks (empty = all)
|
||||
LIST_ONLY=false # --list flag
|
||||
all_names=() # pre-filter stack names (for error messages)
|
||||
updated_names=() # stack names that were updated
|
||||
updated_detail=() # parallel: "stack: service1, service2"
|
||||
@@ -45,6 +47,7 @@ that have updates.
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message
|
||||
-l, --list List running stacks and exit
|
||||
-s, --stack <name> Target a specific stack (repeatable)
|
||||
|
||||
No options = update all running stacks.
|
||||
@@ -56,6 +59,7 @@ EOF
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|--help) usage ;;
|
||||
-l|--list) LIST_ONLY=true; shift ;;
|
||||
-s|--stack)
|
||||
shift
|
||||
[[ $# -eq 0 ]] && { echo -e " ${RED}✗${RESET} Option --stack requires a name." >&2; exit 1; }
|
||||
@@ -103,6 +107,10 @@ for name in "${names[@]}"; do
|
||||
done
|
||||
echo ""
|
||||
|
||||
if $LIST_ONLY; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ── Spinner for long operations ─────────────────────────────────────
|
||||
_spin_kill=""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user