Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8949711

Browse files
committedJan 24, 2025··
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 <pawel.gronowski@docker.com>
1 parent 670150b commit 8949711

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 

‎cli/command/image/tree.go

+24
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
245245
DetailsValue: func(d *imageDetails) string {
246246
return d.ContentSize
247247
},
248+
// Hide if all content sizes are 0
249+
Hide: func() bool {
250+
zero := units.HumanSize(0.0)
251+
for _, img := range view.images {
252+
if img.Details.ContentSize != zero {
253+
return false
254+
}
255+
for _, sub := range img.Children {
256+
if sub.Details.ContentSize != zero {
257+
return false
258+
}
259+
}
260+
}
261+
return true
262+
},
248263
},
249264
{
250265
Title: "Extra",
@@ -308,7 +323,15 @@ func printImageTree(dockerCLI command.Cli, view treeView) error {
308323
// adjustColumns adjusts the width of the first column to maximize the space
309324
// available for image names and removes any columns that would be too narrow
310325
// to display their content.
326+
// Also removes any columns that should not be displayed.
311327
func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColumn {
328+
for idx := len(columns) - 1; idx >= 0; idx-- {
329+
h := columns[idx]
330+
if h.Hide != nil && h.Hide() {
331+
columns = append(columns[:idx], columns[idx+1:]...)
332+
}
333+
}
334+
312335
nameWidth := int(width)
313336
for idx, h := range columns {
314337
if h.Width == 0 {
@@ -429,6 +452,7 @@ type imgColumn struct {
429452

430453
DetailsValue func(*imageDetails) string
431454
Color *aec.ANSI
455+
Hide func() bool
432456
}
433457

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

0 commit comments

Comments
 (0)
Please sign in to comment.