summaryrefslogtreecommitdiff
path: root/cmd/podman/images.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2018-05-30 10:03:46 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2018-05-30 16:30:20 +0000
commit9ace06e0c2ca7f416b6b3f7252791013306dd4f9 (patch)
treef1cbf3ba5c9b9e0a8abfc8861cff5c7a402b91ce /cmd/podman/images.go
parent71487466fb43c2d7960e879c291aae4890506e15 (diff)
downloadpodman-9ace06e0c2ca7f416b6b3f7252791013306dd4f9.tar.gz
podman-9ace06e0c2ca7f416b6b3f7252791013306dd4f9.tar.bz2
podman-9ace06e0c2ca7f416b6b3f7252791013306dd4f9.zip
sort containers and images by create time
When running podman ps or podman images, the containers and images should be sorted by newest to oldest. Resolves: #830 Signed-off-by: baude <bbaude@redhat.com> Closes: #848 Approved by: mheon
Diffstat (limited to 'cmd/podman/images.go')
-rw-r--r--cmd/podman/images.go39
1 files changed, 26 insertions, 13 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index 305d2f11e..6c8af4512 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -14,15 +14,17 @@ import (
"github.com/projectatomic/libpod/libpod"
"github.com/projectatomic/libpod/libpod/image"
"github.com/urfave/cli"
+ "sort"
)
type imagesTemplateParams struct {
- Repository string
- Tag string
- ID string
- Digest digest.Digest
- Created string
- Size string
+ Repository string
+ Tag string
+ ID string
+ Digest digest.Digest
+ Created string
+ CreatedTime time.Time
+ Size string
}
type imagesJSONParams struct {
@@ -42,6 +44,13 @@ type imagesOptions struct {
outputformat string
}
+// Type declaration and functions for sorting the PS output by time
+type imagesSorted []imagesTemplateParams
+
+func (a imagesSorted) Len() int { return len(a) }
+func (a imagesSorted) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
+func (a imagesSorted) Less(i, j int) bool { return a[i].CreatedTime.After(a[j].CreatedTime) }
+
var (
imagesFlags = []cli.Flag{
cli.BoolFlag{
@@ -183,7 +192,7 @@ func imagesToGeneric(templParams []imagesTemplateParams, JSONParams []imagesJSON
}
// getImagesTemplateOutput returns the images information to be printed in human readable format
-func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions) (imagesOutput []imagesTemplateParams) {
+func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, images []*image.Image, opts imagesOptions) (imagesOutput imagesSorted) {
for _, img := range images {
createdTime := img.Created()
@@ -199,17 +208,21 @@ func getImagesTemplateOutput(ctx context.Context, runtime *libpod.Runtime, image
size = nil
}
params := imagesTemplateParams{
- Repository: repo,
- Tag: tag,
- ID: imageID,
- Digest: img.Digest(),
- Created: units.HumanDuration(time.Since((createdTime))) + " ago",
- Size: units.HumanSizeWithPrecision(float64(*size), 3),
+ Repository: repo,
+ Tag: tag,
+ ID: imageID,
+ Digest: img.Digest(),
+ CreatedTime: createdTime,
+ Created: units.HumanDuration(time.Since((createdTime))) + " ago",
+ Size: units.HumanSizeWithPrecision(float64(*size), 3),
}
imagesOutput = append(imagesOutput, params)
}
}
}
+
+ // Sort images by created time
+ sort.Sort(imagesSorted(imagesOutput))
return
}