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

image/tree: Hide Content size column without containerd store #5771

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
24 changes: 24 additions & 0 deletions cli/command/image/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
DetailsValue: func(d *imageDetails) string {
return d.ContentSize
},
// Hide if all content sizes are 0
Hide: func() bool {
zero := units.HumanSize(0.0)
for _, img := range view.images {
if img.Details.ContentSize != zero {
return false
}
for _, sub := range img.Children {
if sub.Details.ContentSize != zero {
return false
}
}
}
return true
},
},
{
Title: "Extra",
Expand Down Expand Up @@ -289,7 +304,15 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
// adjustColumns adjusts the width of the first column to maximize the space
// available for image names and removes any columns that would be too narrow
// to display their content.
// Also removes any columns that should not be displayed.
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
for idx := len(columns) - 1; idx >= 0; idx-- {
h := columns[idx]
if h.Hide != nil && h.Hide() {
columns = append(columns[:idx], columns[idx+1:]...)
}
}

nameWidth := int(width)
for idx, h := range columns {
if h.Width == 0 {
Expand Down Expand Up @@ -410,6 +433,7 @@ type imgColumn struct {

DetailsValue func(*imageDetails) string
Color *aec.ANSI
Hide func() bool
}

func (h imgColumn) Print(clr aec.ANSI, s string) string {
Expand Down
Loading