Skip to content

Commit f6212c0

Browse files
committed
image/list: Show collapsed tree by default
Use the new tree view by default and only fallback if format or old view-related options are used. The expanded view is shown when `--tree` is passed. Signed-off-by: Paweł Gronowski <[email protected]>
1 parent 171a9b7 commit f6212c0

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

cli/command/image/list.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,37 @@ func runImages(ctx context.Context, dockerCLI command.Cli, options imagesOptions
8585
filters.Add("reference", options.matchName)
8686
}
8787

88-
if options.tree {
89-
if options.quiet {
88+
useTree := true
89+
if options.quiet {
90+
if options.tree {
9091
return errors.New("--quiet is not yet supported with --tree")
9192
}
92-
if options.noTrunc {
93+
useTree = false
94+
}
95+
if options.noTrunc {
96+
if options.tree {
9397
return errors.New("--no-trunc is not yet supported with --tree")
9498
}
95-
if options.showDigests {
99+
useTree = false
100+
}
101+
if options.showDigests {
102+
if options.tree {
96103
return errors.New("--show-digest is not yet supported with --tree")
97104
}
98-
if options.format != "" {
105+
useTree = false
106+
}
107+
if options.format != "" {
108+
if options.tree {
99109
return errors.New("--format is not yet supported with --tree")
100110
}
111+
useTree = false
112+
}
101113

114+
if useTree {
102115
return runTree(ctx, dockerCLI, treeOptions{
103-
all: options.all,
104-
filters: filters,
116+
all: options.all,
117+
filters: filters,
118+
expanded: options.tree,
105119
})
106120
}
107121

cli/command/image/tree.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ import (
2424
)
2525

2626
type treeOptions struct {
27-
all bool
28-
filters client.Filters
27+
all bool
28+
filters client.Filters
29+
expanded bool
2930
}
3031

3132
type treeView struct {
@@ -54,7 +55,7 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
5455
attested := make(map[digest.Digest]bool)
5556

5657
for _, img := range images {
57-
details := imageDetails{
58+
topDetails := imageDetails{
5859
ID: img.ID,
5960
DiskUsage: units.HumanSizeWithPrecision(float64(img.Size), 3),
6061
InUse: img.Containers > 0,
@@ -73,33 +74,38 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
7374
continue
7475
}
7576

77+
inUse := len(im.ImageData.Containers) > 0
78+
if inUse {
79+
// Mark top-level parent image as used if any of its subimages are used.
80+
topDetails.InUse = true
81+
}
82+
83+
if !opts.expanded {
84+
continue
85+
}
86+
7687
sub := subImage{
7788
Platform: platforms.Format(im.ImageData.Platform),
7889
Available: im.Available,
7990
Details: imageDetails{
8091
ID: im.ID,
8192
DiskUsage: units.HumanSizeWithPrecision(float64(im.Size.Total), 3),
82-
InUse: len(im.ImageData.Containers) > 0,
93+
InUse: inUse,
8394
ContentSize: units.HumanSizeWithPrecision(float64(im.Size.Content), 3),
8495
},
8596
}
8697

87-
if sub.Details.InUse {
88-
// Mark top-level parent image as used if any of its subimages are used.
89-
details.InUse = true
90-
}
91-
9298
children = append(children, sub)
9399

94100
// Add extra spacing between images if there's at least one entry with children.
95101
view.imageSpacing = true
96102
}
97103

98-
details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3)
104+
topDetails.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3)
99105

100106
view.images = append(view.images, topImage{
101107
Names: img.RepoTags,
102-
Details: details,
108+
Details: topDetails,
103109
Children: children,
104110
created: img.Created,
105111
})

0 commit comments

Comments
 (0)