1
0
mirror of https://github.com/docker/cli.git synced 2026-10-31 11:35:26 +03:00

Merge pull request #6873 from thaJeztah/simplify_chips

cli/command/image: getPossibleChips: simplify
This commit is contained in:
Paweł Gronowski
2026-04-02 13:51:17 +02:00
committed by GitHub

View File

@@ -206,30 +206,38 @@ var allChips = []imageChip{
chipInUse,
}
// getPossibleChips returns the list of chips used by at least one image.
// It is used to determine which columns to print (and how much width to
// reserve).
func getPossibleChips(view treeView) (chips []imageChip) {
remaining := make([]imageChip, len(allChips))
copy(remaining, allChips)
remaining := slices.Clone(allChips)
var possible []imageChip
for _, img := range view.images {
details := []imageDetails{img.Details}
for _, c := range img.Children {
details = append(details, c.Details)
check := func(d imageDetails) (done bool) {
// filter without allocating
out := remaining[:0]
for _, chip := range remaining {
if chip.check(&d) {
chips = append(chips, chip)
continue
}
out = append(out, chip)
}
remaining = out
return len(remaining) == 0
}
for _, d := range details {
for idx := len(remaining) - 1; idx >= 0; idx-- {
chip := remaining[idx]
if chip.check(&d) {
possible = append(possible, chip)
remaining = append(remaining[:idx], remaining[idx+1:]...)
}
for _, img := range view.images {
if check(img.Details) {
return chips
}
for _, c := range img.Children {
if check(c.Details) {
return chips
}
}
}
return possible
return chips
}
func printImageTree(outs command.Streams, view treeView) {