From 54a4ab135fe98fc89ef1af3cda021130be60b265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Mon, 19 Aug 2024 12:11:52 +0200 Subject: [PATCH] list/tree: Hide `Used` column if no truthy value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't show the `Used` column in the image tree view when no image is actually used and the column would be empty. Signed-off-by: Paweł Gronowski --- cli/command/image/tree.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index a8ecd4fc9e8b..15ea137f3335 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -3,6 +3,7 @@ package image import ( "context" "fmt" + "slices" "sort" "strings" "unicode/utf8" @@ -25,6 +26,9 @@ type treeOptions struct { type treeView struct { images []topImage + // showUsed indicates whether the "Used" column should be shown. + showUsed bool + // imageSpacing indicates whether there should be extra spacing between images. imageSpacing bool } @@ -71,6 +75,9 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error if sub.Details.Used { // Mark top-level parent image as used if any of its subimages are used. details.Used = true + + // Show the Used column only if there will be at least one non-zero value. + view.showUsed = true } totalContent += im.Size.Content @@ -192,6 +199,12 @@ func printImageTree(dockerCLI command.Cli, view treeView) error { }, } + if !view.showUsed { + columns = slices.DeleteFunc(columns, func(c imgColumn) bool { + return c.Title == "Used" + }) + } + nameWidth := int(width) for idx, h := range columns { if h.Width == 0 {