summaryrefslogtreecommitdiff
path: root/cmd/podman/images
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-04-22 17:33:13 -0700
committerJhon Honce <jhonce@redhat.com>2020-04-29 08:24:56 -0700
commita9cc13448ee3185bb63f4c3eef94e755e79b8571 (patch)
treee91e17ca9c46540aedbec46e7268ba5f65b24d0c /cmd/podman/images
parent27aa3a7837fa1c5379ff7ca1a9dcd6416b2ac685 (diff)
downloadpodman-a9cc13448ee3185bb63f4c3eef94e755e79b8571.tar.gz
podman-a9cc13448ee3185bb63f4c3eef94e755e79b8571.tar.bz2
podman-a9cc13448ee3185bb63f4c3eef94e755e79b8571.zip
V2 Restore images list tests
* Fix history --quiet formatting * Fix image inspect --format=json * Fix image list --sort Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/images')
-rw-r--r--cmd/podman/images/history.go20
-rw-r--r--cmd/podman/images/list.go72
-rw-r--r--cmd/podman/images/rm.go5
3 files changed, 65 insertions, 32 deletions
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index b8d216cc1..ce153aa46 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -89,22 +89,20 @@ func history(cmd *cobra.Command, args []string) error {
hdr := "ID\tCREATED\tCREATED BY\tSIZE\tCOMMENT\n"
row := "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- if len(opts.format) > 0 {
+ switch {
+ case len(opts.format) > 0:
hdr = ""
row = opts.format
if !strings.HasSuffix(opts.format, "\n") {
row += "\n"
}
- } else {
- switch {
- case opts.human:
- row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- case opts.noTrunc:
- row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
- case opts.quiet:
- hdr = ""
- row = "{{.ID}}\n"
- }
+ case opts.quiet:
+ hdr = ""
+ row = "{{.ID}}\n"
+ case opts.human:
+ row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
+ case opts.noTrunc:
+ row = "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
}
format := hdr + "{{range . }}" + row + "{{end}}"
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 552fed804..83c039ed3 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -99,14 +99,29 @@ func images(cmd *cobra.Command, args []string) error {
return err
}
- imageS := summaries
- sort.Slice(imageS, sortFunc(listFlag.sort, imageS))
+ switch {
+ case listFlag.quiet:
+ return writeId(summaries)
+ case cmd.Flag("format").Changed && listFlag.format == "json":
+ return writeJSON(summaries)
+ default:
+ return writeTemplate(summaries)
+ }
+}
- if cmd.Flag("format").Changed && listFlag.format == "json" {
- return writeJSON(imageS)
- } else {
- return writeTemplate(imageS, err)
+func writeId(imageS []*entities.ImageSummary) error {
+ var ids = map[string]struct{}{}
+ for _, e := range imageS {
+ i := "sha256:" + e.ID
+ if !listFlag.noTrunc {
+ i = fmt.Sprintf("%12.12s", e.ID)
+ }
+ ids[i] = struct{}{}
}
+ for k := range ids {
+ fmt.Fprint(os.Stdout, k+"\n")
+ }
+ return nil
}
func writeJSON(imageS []*entities.ImageSummary) error {
@@ -131,7 +146,7 @@ func writeJSON(imageS []*entities.ImageSummary) error {
return enc.Encode(imgs)
}
-func writeTemplate(imageS []*entities.ImageSummary, err error) error {
+func writeTemplate(imageS []*entities.ImageSummary) error {
var (
hdr, row string
)
@@ -143,10 +158,11 @@ func writeTemplate(imageS []*entities.ImageSummary, err error) error {
h.Repository, h.Tag = tokenRepoTag(tag)
imgs = append(imgs, h)
}
- if e.IsReadOnly() {
- listFlag.readOnly = true
- }
+ listFlag.readOnly = e.IsReadOnly()
}
+
+ sort.Slice(imgs, sortFunc(listFlag.sort, imgs))
+
if len(listFlag.format) < 1 {
hdr, row = imageListFormat(listFlag)
} else {
@@ -176,37 +192,33 @@ func tokenRepoTag(tag string) (string, string) {
}
}
-func sortFunc(key string, data []*entities.ImageSummary) func(i, j int) bool {
+func sortFunc(key string, data []imageReporter) func(i, j int) bool {
switch key {
case "id":
return func(i, j int) bool {
- return data[i].ID < data[j].ID
+ return data[i].ID() < data[j].ID()
}
case "repository":
return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
+ return data[i].Repository < data[j].Repository
}
case "size":
return func(i, j int) bool {
- return data[i].Size < data[j].Size
+ return data[i].size() < data[j].size()
}
case "tag":
return func(i, j int) bool {
- return data[i].RepoTags[0] < data[j].RepoTags[0]
+ return data[i].Tag < data[j].Tag
}
default:
// case "created":
return func(i, j int) bool {
- return data[i].Created.After(data[j].Created)
+ return data[i].created().After(data[j].created())
}
}
}
func imageListFormat(flags listFlagType) (string, string) {
- if flags.quiet {
- return "", "{{.ID}}\n"
- }
-
// Defaults
hdr := "REPOSITORY\tTAG"
row := "{{.Repository}}\t{{if .Tag}}{{.Tag}}{{else}}<none>{{end}}"
@@ -263,6 +275,10 @@ func (i imageReporter) Created() string {
return units.HumanDuration(time.Since(i.ImageSummary.Created)) + " ago"
}
+func (i imageReporter) created() time.Time {
+ return i.ImageSummary.Created
+}
+
func (i imageReporter) Size() string {
s := units.HumanSizeWithPrecision(float64(i.ImageSummary.Size), 3)
j := strings.LastIndexFunc(s, unicode.IsNumber)
@@ -272,3 +288,19 @@ func (i imageReporter) Size() string {
func (i imageReporter) History() string {
return strings.Join(i.ImageSummary.History, ", ")
}
+
+func (i imageReporter) CreatedAt() string {
+ return i.ImageSummary.Created.String()
+}
+
+func (i imageReporter) CreatedSince() string {
+ return i.Created()
+}
+
+func (i imageReporter) CreatedTime() string {
+ return i.CreatedAt()
+}
+
+func (i imageReporter) size() int64 {
+ return i.ImageSummary.Size
+}
diff --git a/cmd/podman/images/rm.go b/cmd/podman/images/rm.go
index da6a90d2b..1cf5fa365 100644
--- a/cmd/podman/images/rm.go
+++ b/cmd/podman/images/rm.go
@@ -54,7 +54,10 @@ func rm(cmd *cobra.Command, args []string) error {
fmt.Println("Untagged: " + u)
}
for _, d := range report.Deleted {
- fmt.Println("Deleted: " + d)
+ // Make sure an image was deleted (and not just untagged); else print it
+ if len(d) > 0 {
+ fmt.Println("Deleted: " + d)
+ }
}
registry.SetExitCode(report.ExitCode)
}