Skip to content

Commit 203ce87

Browse files
committed
image/tree: Hide Content size column without containerd store
With graph drivers, all content sizes are zero because the compressed content isn't stored. This makes the whole column useless and wasting the terminal space. Hide the whole column if all its values would be zero. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 5b90e0e commit 203ce87

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

cli/command/image/tree.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,21 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
226226
DetailsValue: func(d *imageDetails) string {
227227
return d.ContentSize
228228
},
229+
// Hide if all content sizes are 0
230+
Hide: func() bool {
231+
zero := units.HumanSize(0.0)
232+
for _, img := range view.images {
233+
if img.Details.ContentSize != zero {
234+
return false
235+
}
236+
for _, sub := range img.Children {
237+
if sub.Details.ContentSize != zero {
238+
return false
239+
}
240+
}
241+
}
242+
return true
243+
},
229244
},
230245
{
231246
Title: "Extra",
@@ -289,7 +304,15 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
289304
// adjustColumns adjusts the width of the first column to maximize the space
290305
// available for image names and removes any columns that would be too narrow
291306
// to display their content.
307+
// Also removes any columns that should not be displayed.
292308
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
309+
for idx := len(columns) - 1; idx >= 0; idx-- {
310+
h := columns[idx]
311+
if h.Hide != nil && h.Hide() {
312+
columns = append(columns[:idx], columns[idx+1:]...)
313+
}
314+
}
315+
293316
nameWidth := int(width)
294317
for idx, h := range columns {
295318
if h.Width == 0 {
@@ -410,6 +433,7 @@ type imgColumn struct {
410433

411434
DetailsValue func(*imageDetails) string
412435
Color *aec.ANSI
436+
Hide func() bool
413437
}
414438

415439
func (h imgColumn) Print(clr aec.ANSI, s string) string {

0 commit comments

Comments
 (0)