list/tree: Sort by created date

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
(cherry picked from commit b1a08f7841)
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski 2024-08-16 11:32:37 +02:00
parent 44a9ffa0ad
commit 324cc5d30f
No known key found for this signature in database
GPG Key ID: B85EFCFE26DEF92A
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package image
import ( import (
"context" "context"
"fmt" "fmt"
"sort"
"strings" "strings"
"unicode/utf8" "unicode/utf8"
@ -68,13 +69,19 @@ 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)
view = append(view, topImage{ view = append(view, topImage{
Names: img.RepoTags, Names: img.RepoTags,
Details: details, Details: details,
Children: children, Children: children,
created: img.Created,
}) })
} }
sort.Slice(view, func(i, j int) bool {
return view[i].created > view[j].created
})
return printImageTree(dockerCLI, view) return printImageTree(dockerCLI, view)
} }
@ -89,6 +96,8 @@ type topImage struct {
Names []string Names []string
Details imageDetails Details imageDetails
Children []subImage Children []subImage
created int64
} }
type subImage struct { type subImage struct {