Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list/tree: Hide Used column if no truthy value #5357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cli/command/image/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package image
import (
"context"
"fmt"
"slices"
"sort"
"strings"
"unicode/utf8"
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading