refactor: use dynamic Docker-style tables for stack listings
This commit is contained in:
1 parent
fdcc47cb5b
commit
100caa0e88
1 file changed
+41
-23
@@ -582,11 +582,34 @@ run_all_sequential() {
|
||||
fi
|
||||
}
|
||||
|
||||
print_table() {
|
||||
local columns="$1"
|
||||
shift
|
||||
local -a cells=("$@") widths=()
|
||||
local index column row
|
||||
|
||||
for ((index = 0; index < ${#cells[@]}; index++)); do
|
||||
column=$((index % columns))
|
||||
if ((${#cells[index]} > ${widths[column]:-0})); then
|
||||
widths[column]="${#cells[index]}"
|
||||
fi
|
||||
done
|
||||
|
||||
for ((row = 0; row < ${#cells[@]}; row += columns)); do
|
||||
for ((column = 0; column < columns; column++)); do
|
||||
((column > 0)) && printf ' '
|
||||
if ((column == columns - 1)); then
|
||||
printf '%s\n' "${cells[row + column]}"
|
||||
else
|
||||
printf '%-*s' "${widths[column]}" "${cells[row + column]}"
|
||||
fi
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
list_stacks() {
|
||||
local stack stage_name status
|
||||
|
||||
printf '%-24s %-16s %s\n' "STACK" "STAGE" "STATUS"
|
||||
printf '%-24s %-16s %s\n' "------------------------" "----------------" "---------------"
|
||||
local -a cells=(STACK STAGE STATUS)
|
||||
|
||||
for stack in "${DISCOVERED_STACKS[@]}"; do
|
||||
if contains "$stack" "${EXCLUDED_STACKS[@]}"; then
|
||||
@@ -597,40 +620,35 @@ list_stacks() {
|
||||
status="managed"
|
||||
fi
|
||||
|
||||
printf '%-24s %-16s %s\n' "$stack" "$stage_name" "$status"
|
||||
cells+=("$stack" "$stage_name" "$status")
|
||||
done
|
||||
}
|
||||
|
||||
stack_images() {
|
||||
local stack="$1"
|
||||
local output image
|
||||
|
||||
output="$(compose "$stack" config --images)" || return 1
|
||||
|
||||
while IFS= read -r image; do
|
||||
[[ -n "$image" ]] || continue
|
||||
printf '%-24s %s\n' "$stack" "$image"
|
||||
done <<<"$output"
|
||||
print_table 3 "${cells[@]}"
|
||||
}
|
||||
|
||||
list_images() {
|
||||
local target="${1:-}"
|
||||
local stack
|
||||
local stack output image
|
||||
local failed=0
|
||||
|
||||
printf '%-24s %s\n' "STACK" "IMAGE"
|
||||
printf '%-24s %s\n' "------------------------" "----------------------------------------"
|
||||
local -a stacks=("${MANAGED_STACKS[@]}") cells=(STACK IMAGE)
|
||||
|
||||
if [[ -n "$target" ]]; then
|
||||
require_target "images" "$target"
|
||||
stack_images "$target"
|
||||
return
|
||||
stacks=("$target")
|
||||
fi
|
||||
|
||||
for stack in "${MANAGED_STACKS[@]}"; do
|
||||
stack_images "$stack" || ((failed += 1))
|
||||
for stack in "${stacks[@]}"; do
|
||||
if ! output="$(compose "$stack" config --images)"; then
|
||||
((failed += 1))
|
||||
continue
|
||||
fi
|
||||
while IFS= read -r image; do
|
||||
[[ -n "$image" ]] || continue
|
||||
cells+=("$stack" "$image")
|
||||
done <<<"$output"
|
||||
done
|
||||
|
||||
print_table 2 "${cells[@]}"
|
||||
((failed == 0))
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user