feat: show service names in image listings

This commit is contained in:
lingkai5wu committed 2026-10-10 20:46:41 +08:00
1 parent 100caa0e88
commit 85f6acb264
1 file changed
+24 -8
+24 -8
View File
@@ -84,7 +84,7 @@ Inspect:
ps [STACK] Show container status
logs STACK Follow logs
config STACK Render Compose configuration
images [STACK] Show configured images and versions
images [STACK] Show services, configured images, and versions
list List stacks, stages, and management status
help, -h, --help Show this help
@@ -628,9 +628,9 @@ list_stacks() {
list_images() {
local target="${1:-}"
local stack output image
local stack output service image
local failed=0
local -a stacks=("${MANAGED_STACKS[@]}") cells=(STACK IMAGE)
local -a stacks=("${MANAGED_STACKS[@]}") cells=(STACK SERVICE IMAGE)
if [[ -n "$target" ]]; then
require_target "images" "$target"
@@ -638,17 +638,33 @@ list_images() {
fi
for stack in "${stacks[@]}"; do
if ! output="$(compose "$stack" config --images)"; then
# Read service/image pairs from Compose's canonical YAML (two-space indent).
if ! output="$(compose "$stack" config --format yaml | awk -v project="$stack" '
{ gsub(/["\047]/, "") }
/^name: / { project = $2 }
/^[^ ]/ { in_services = ($0 == "services:") }
in_services && /^ [^ ]/ {
service = $1
sub(/:$/, "", service)
services[++count] = service
images[service] = project "-" service
}
in_services && /^ image: / { images[service] = $2 }
END {
for (i = 1; i <= count; i++)
print services[i] "\t" images[services[i]]
}
')"; then
((failed += 1))
continue
fi
while IFS= read -r image; do
[[ -n "$image" ]] || continue
cells+=("$stack" "$image")
while IFS=$'\t' read -r service image; do
[[ -n "$service" ]] || continue
cells+=("$stack" "$service" "$image")
done <<<"$output"
done
print_table 2 "${cells[@]}"
print_table 3 "${cells[@]}"
((failed == 0))
}