docker-stacks-update: add -s/--stack to target specific stacks
Usage: docker-stacks-update -s stack_a -s stack_b Only matching running stacks are processed. Shows a helpful message with available stacks if no match is found.
This commit is contained in:
@@ -20,6 +20,8 @@ if command -v tput >/dev/null 2>&1 && [ -t 1 ]; then
|
||||
fi
|
||||
|
||||
# ── State ───────────────────────────────────────────────────────────
|
||||
TARGET_STACKS=() # user-specified stacks (empty = all)
|
||||
all_names=() # pre-filter stack names (for error messages)
|
||||
updated_names=() # stack names that were updated
|
||||
updated_detail=() # parallel: "stack: service1, service2"
|
||||
unchanged_names=() # stack names already up to date
|
||||
@@ -42,7 +44,8 @@ Pull latest images and restart all running Docker Compose stacks
|
||||
that have updates.
|
||||
|
||||
Options:
|
||||
-h, --help Show this help message
|
||||
-h, --help Show this help message
|
||||
-s, --stack <name> Target a specific stack (repeatable)
|
||||
|
||||
No options = update all running stacks.
|
||||
EOF
|
||||
@@ -50,10 +53,19 @@ EOF
|
||||
}
|
||||
|
||||
# ── Parse arguments ──────────────────────────────────────────────────
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|--help) usage ;;
|
||||
*) echo -e " ${RED}✗${RESET} Unknown option: ${arg}" >&2; usage ;;
|
||||
-s|--stack)
|
||||
shift
|
||||
[[ $# -eq 0 ]] && { echo -e " ${RED}✗${RESET} Option --stack requires a name." >&2; exit 1; }
|
||||
TARGET_STACKS+=("$1")
|
||||
shift
|
||||
;;
|
||||
-*)
|
||||
echo -e " ${RED}✗${RESET} Unknown option: $1" >&2; usage ;;
|
||||
*)
|
||||
echo -e " ${RED}✗${RESET} Unexpected argument: $1" >&2; usage ;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -117,6 +129,31 @@ _spin_stop() {
|
||||
echo -ne "\r\033[K"
|
||||
}
|
||||
|
||||
# ── Filter stacks if --stack was given ───────────────────────────────
|
||||
if [[ ${#TARGET_STACKS[@]} -gt 0 ]]; then
|
||||
all_names=("${names[@]}")
|
||||
filtered_names=()
|
||||
filtered_configs=()
|
||||
for i in "${!names[@]}"; do
|
||||
for t in "${TARGET_STACKS[@]}"; do
|
||||
if [[ "${names[$i]}" == "$t" ]]; then
|
||||
filtered_names+=("${names[$i]}")
|
||||
filtered_configs+=("${configs[$i]}")
|
||||
break
|
||||
fi
|
||||
done
|
||||
done
|
||||
names=("${filtered_names[@]}")
|
||||
configs=("${filtered_configs[@]}")
|
||||
if [[ ${#names[@]} -eq 0 ]]; then
|
||||
warn "No running stacks match the requested name(s)."
|
||||
echo " ${CYAN}→${RESET} Running stacks: ${all_names[*]}"
|
||||
exit 0
|
||||
fi
|
||||
echo " ${CYAN}→${RESET} Targeting ${BOLD}${#names[@]}${RESET} of ${BOLD}${total}${RESET} running stack(s)"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ── Process each stack ──────────────────────────────────────────────
|
||||
for i in "${!names[@]}"; do
|
||||
stack="${names[$i]}"
|
||||
|
||||
Reference in New Issue
Block a user