summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-02-13 11:42:47 +0100
committerGitHub <noreply@github.com>2020-02-13 11:42:47 +0100
commit2814995a9281b3b8e67d7c48df28de0de742b995 (patch)
tree619e916a4e18ac1f802596700c6a5c0418ebe184 /cmd
parenta9969c23a343e675d9a628cd5d9456523aaea5b7 (diff)
parent3afd1b5a7c40e2a55ffd93b9a987385daa3047c0 (diff)
downloadpodman-2814995a9281b3b8e67d7c48df28de0de742b995.tar.gz
podman-2814995a9281b3b8e67d7c48df28de0de742b995.tar.bz2
podman-2814995a9281b3b8e67d7c48df28de0de742b995.zip
Merge pull request #5115 from QiWang19/images-format
images --format compatible with docker
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/images.go59
1 files changed, 36 insertions, 23 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index 115f30d9b..de61690ae 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -21,16 +21,16 @@ import (
)
type imagesTemplateParams struct {
- Repository string
- Tag string
- ID string
- Digest digest.Digest
- Digests []digest.Digest
- Created string
- CreatedTime time.Time
- Size string
- ReadOnly bool
- History string
+ Repository string
+ Tag string
+ ID string
+ Digest digest.Digest
+ Digests []digest.Digest
+ CreatedAt time.Time
+ CreatedSince string
+ Size string
+ ReadOnly bool
+ History string
}
type imagesJSONParams struct {
@@ -65,7 +65,7 @@ func (a imagesSorted) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type imagesSortedCreated struct{ imagesSorted }
func (a imagesSortedCreated) Less(i, j int) bool {
- return a.imagesSorted[i].CreatedTime.After(a.imagesSorted[j].CreatedTime)
+ return a.imagesSorted[i].CreatedAt.After(a.imagesSorted[j].CreatedAt)
}
type imagesSortedID struct{ imagesSorted }
@@ -185,7 +185,17 @@ func imagesCmd(c *cliconfig.ImagesValues) error {
history: c.History,
}
- opts.outputformat = opts.setOutputFormat()
+ outputformat := opts.setOutputFormat()
+ // These fields were renamed, so we need to provide backward compat for
+ // the old names.
+ if strings.Contains(outputformat, "{{.Created}}") {
+ outputformat = strings.Replace(outputformat, "{{.Created}}", "{{.CreatedSince}}", -1)
+ }
+ if strings.Contains(outputformat, "{{.CreatedTime}}") {
+ outputformat = strings.Replace(outputformat, "{{.CreatedTime}}", "{{.CreatedAt}}", -1)
+ }
+ opts.outputformat = outputformat
+
filteredImages, err := runtime.GetFilteredImages(filters, false)
if err != nil {
return errors.Wrapf(err, "unable to get images")
@@ -216,7 +226,7 @@ func (i imagesOptions) setOutputFormat() string {
if i.digests {
format += "{{.Digest}}\t"
}
- format += "{{.ID}}\t{{.Created}}\t{{.Size}}\t"
+ format += "{{.ID}}\t{{.CreatedSince}}\t{{.Size}}\t"
if i.history {
format += "{{if .History}}{{.History}}{{else}}<none>{{end}}\t"
}
@@ -301,16 +311,16 @@ func getImagesTemplateOutput(ctx context.Context, images []*adapter.ContainerIma
imageDigest = img.Digest()
}
params := imagesTemplateParams{
- Repository: repo,
- Tag: tag,
- ID: imageID,
- Digest: imageDigest,
- Digests: img.Digests(),
- CreatedTime: createdTime,
- Created: units.HumanDuration(time.Since(createdTime)) + " ago",
- Size: sizeStr,
- ReadOnly: img.IsReadOnly(),
- History: strings.Join(img.NamesHistory(), ", "),
+ Repository: repo,
+ Tag: tag,
+ ID: imageID,
+ Digest: imageDigest,
+ Digests: img.Digests(),
+ CreatedAt: createdTime,
+ CreatedSince: units.HumanDuration(time.Since(createdTime)) + " ago",
+ Size: sizeStr,
+ ReadOnly: img.IsReadOnly(),
+ History: strings.Join(img.NamesHistory(), ", "),
}
imagesOutput = append(imagesOutput, params)
if opts.quiet { // Show only one image ID when quiet
@@ -384,6 +394,9 @@ func GenImageOutputMap() map[string]string {
values[key] = "R/O"
continue
}
+ if value == "CreatedSince" {
+ value = "created"
+ }
values[key] = strings.ToUpper(splitCamelCase(value))
}
return values