refactor: unify grouped execution order

This commit is contained in:
lingkai5wu committed 2026-10-10 17:17:17 +08:00
1 parent 3da799a526
commit 48ddc3e728
1 file changed
+31 -16
+31 -16
View File
@@ -335,12 +335,30 @@ run_group() {
fi
case "$action" in
up | start) working_result="Starting"; success_result="Started" ;;
restart) working_result="Restarting"; success_result="Restarted" ;;
stop) working_result="Stopping"; success_result="Stopped" ;;
down) working_result="Removing"; success_result="Removed" ;;
pull) working_result="Pulling"; success_result="Pulled" ;;
update) working_result="Updating"; success_result="Updated" ;;
up | start)
working_result="Starting"
success_result="Started"
;;
restart)
working_result="Restarting"
success_result="Restarted"
;;
stop)
working_result="Stopping"
success_result="Stopped"
;;
down)
working_result="Removing"
success_result="Removed"
;;
pull)
working_result="Pulling"
success_result="Pulled"
;;
update)
working_result="Updating"
success_result="Updated"
;;
esac
while :; do
@@ -438,6 +456,7 @@ collect_skipped_groups() {
run_all_grouped() {
local action="$1"
local direction="forward"
local start=0 end="${#GROUP_NAMES[@]}" step=1
local i
RUN_SUCCESS=0
@@ -448,22 +467,18 @@ run_all_grouped() {
if [[ "$action" == "stop" || "$action" == "down" ]]; then
direction="reverse"
for ((i = ${#GROUP_NAMES[@]} - 1; i >= 0; i--)); do
start=$((end - 1))
end=-1
step=-1
fi
for ((i = start; i != end; i += step)); do
if ! run_group "$i" "$action"; then
collect_skipped_groups "$i" "$direction"
print_run_summary
return 1
fi
done
else
for ((i = 0; i < ${#GROUP_NAMES[@]}; i++)); do
if ! run_group "$i" "$action"; then
collect_skipped_groups "$i" "$direction"
print_run_summary
return 1
fi
done
fi
print_run_summary
}