refactor: simplify stack management state
This commit is contained in:
1 parent
fc2504df5a
commit
74b6f8ad74
1 file changed
+10
-27
@@ -88,14 +88,14 @@ validate_name() {
|
||||
die "invalid $kind name: $value"
|
||||
}
|
||||
|
||||
# manage.conf DSL: set the default concurrency for groups without an override.
|
||||
# Set the default concurrency for groups without an override.
|
||||
max_parallel() {
|
||||
[[ $# -eq 1 ]] || die "max_parallel expects exactly one value"
|
||||
validate_parallel_limit "$1"
|
||||
DEFAULT_MAX_PARALLEL="$1"
|
||||
}
|
||||
|
||||
# manage.conf DSL: declare an ordered group and its stacks.
|
||||
# Declare an ordered group and its stacks.
|
||||
# Usage: group NAME [--parallel N] STACK...
|
||||
group() {
|
||||
[[ $# -ge 2 ]] || die "group expects NAME [--parallel N] STACK..."
|
||||
@@ -134,7 +134,7 @@ group() {
|
||||
CONFIG_GROUP_STACKS+=("$*")
|
||||
}
|
||||
|
||||
# manage.conf DSL: exclude stacks from all bulk operations.
|
||||
# Exclude stacks from all bulk operations.
|
||||
exclude() {
|
||||
[[ $# -ge 1 ]] || die "exclude expects at least one stack"
|
||||
|
||||
@@ -152,16 +152,8 @@ exclude() {
|
||||
load_config() {
|
||||
[[ -f "$CONFIG_FILE" ]] || return 0
|
||||
|
||||
bash -n "$CONFIG_FILE" || die "syntax error in config file: $CONFIG_FILE"
|
||||
# This is a trusted Bash configuration file that calls the DSL above.
|
||||
source "$CONFIG_FILE"
|
||||
|
||||
local legacy
|
||||
for legacy in WHITELIST BLACKLIST PRIORITY; do
|
||||
if declare -p "$legacy" >/dev/null 2>&1; then
|
||||
die "$legacy is no longer supported; migrate $CONFIG_FILE to group/exclude directives"
|
||||
fi
|
||||
done
|
||||
# The trusted config calls max_parallel, group, and exclude above.
|
||||
source "$CONFIG_FILE" || die "cannot load config file: $CONFIG_FILE"
|
||||
}
|
||||
|
||||
discover_stacks() {
|
||||
@@ -427,27 +419,18 @@ run_all_grouped() {
|
||||
run_all_sequential() {
|
||||
local action="$1"
|
||||
local stack
|
||||
|
||||
RUN_SUCCESS=0
|
||||
RUN_FAILED=0
|
||||
RUN_FAILED_STACKS=()
|
||||
RUN_SKIPPED_GROUPS=()
|
||||
local -a failed_stacks=()
|
||||
warn_unassigned
|
||||
|
||||
for stack in "${MANAGED_STACKS[@]}"; do
|
||||
if run_stack "$stack" "$action"; then
|
||||
((RUN_SUCCESS += 1))
|
||||
else
|
||||
((RUN_FAILED += 1))
|
||||
RUN_FAILED_STACKS+=("$stack")
|
||||
fi
|
||||
run_stack "$stack" "$action" || failed_stacks+=("$stack")
|
||||
done
|
||||
|
||||
if ((RUN_FAILED > 0)); then
|
||||
if ((${#failed_stacks[@]} > 0)); then
|
||||
echo
|
||||
echo "Failed stacks: ${RUN_FAILED_STACKS[*]}" >&2
|
||||
echo "Failed stacks: ${failed_stacks[*]}" >&2
|
||||
return 1
|
||||
fi
|
||||
((RUN_FAILED == 0))
|
||||
}
|
||||
|
||||
list_stacks() {
|
||||
|
||||
Reference in new issue
Block a user