mirror of https://github.com/docker/cli.git
Compare commits
3 Commits
8dccdd1d13
...
e66638eb12
Author | SHA1 | Date |
---|---|---|
Sebastiaan van Stijn | e66638eb12 | |
Sebastiaan van Stijn | be3646b87c | |
Sebastiaan van Stijn | 7187c78554 |
|
@ -14,6 +14,7 @@ import (
|
||||||
imagetypes "github.com/docker/docker/api/types/image"
|
imagetypes "github.com/docker/docker/api/types/image"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/go-units"
|
"github.com/docker/go-units"
|
||||||
|
"github.com/fvbommel/sortorder"
|
||||||
"github.com/morikuni/aec"
|
"github.com/morikuni/aec"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,16 +82,46 @@ func runTree(ctx context.Context, dockerCLI command.Cli, opts treeOptions) error
|
||||||
|
|
||||||
details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3)
|
details.ContentSize = units.HumanSizeWithPrecision(float64(totalContent), 3)
|
||||||
|
|
||||||
|
if len(img.RepoTags) == 0 {
|
||||||
|
// Untagged image
|
||||||
view.images = append(view.images, topImage{
|
view.images = append(view.images, topImage{
|
||||||
Names: img.RepoTags,
|
Names: img.RepoTags,
|
||||||
Details: details,
|
Details: details,
|
||||||
Children: children,
|
Children: children,
|
||||||
created: img.Created,
|
created: img.Created,
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
// Present images tagged under multiple names as separate images.
|
||||||
|
for _, n := range img.RepoTags {
|
||||||
|
view.images = append(view.images, topImage{
|
||||||
|
Names: []string{n}, // Consider changing Names to be a single name for purpose of this presentation.
|
||||||
|
Details: details,
|
||||||
|
Children: children,
|
||||||
|
created: img.Created,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort images alphabetically using natural-sort, with untagged images last.
|
||||||
sort.Slice(view.images, func(i, j int) bool {
|
sort.Slice(view.images, func(i, j int) bool {
|
||||||
|
iUntagged, jUntagged := len(view.images[i].Names) == 0, len(view.images[j].Names) == 0
|
||||||
|
if iUntagged || jUntagged {
|
||||||
|
switch {
|
||||||
|
case iUntagged && jUntagged:
|
||||||
|
// Both untagged images; sort by created date (desc)
|
||||||
return view.images[i].created > view.images[j].created
|
return view.images[i].created > view.images[j].created
|
||||||
|
case iUntagged:
|
||||||
|
// Sort untagged images last
|
||||||
|
return false
|
||||||
|
case jUntagged:
|
||||||
|
// Sort untagged images last
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort alphabetically, ascending
|
||||||
|
return sortorder.NaturalLess(view.images[i].Names[0], view.images[j].Names[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
return printImageTree(dockerCLI, view)
|
return printImageTree(dockerCLI, view)
|
||||||
|
|
Loading…
Reference in New Issue