@@ -24,8 +24,9 @@ import (
2424)
2525
2626type treeOptions struct {
27- all bool
28- filters client.Filters
27+ all bool
28+ filters client.Filters
29+ expanded bool
2930}
3031
3132type 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