summaryrefslogtreecommitdiff
path: root/cmd/podman/images/list.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-11-18 09:03:00 -0700
committerJhon Honce <jhonce@redhat.com>2021-12-02 09:07:27 -0700
commit61792de36ea2ea98f6e3aef3821d1b15beebf9e0 (patch)
treef2e73122b2cdb0323e1d38792eef44a625b85d10 /cmd/podman/images/list.go
parentfbcebcb46a2444ce078dee10d8d51555bee8f177 (diff)
downloadpodman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.tar.gz
podman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.tar.bz2
podman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.zip
Refactor podman image command output
Leverage new report.Formatter allowing better compatibility from podman command output. Follow on PR's will cover containers, etc. See #10974 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/images/list.go')
-rw-r--r--cmd/podman/images/list.go33
1 files changed, 13 insertions, 20 deletions
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 01286daf2..61514daa7 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -117,7 +117,7 @@ func images(cmd *cobra.Command, args []string) error {
listOptions.Filter = append(listOptions.Filter, "reference="+args[0])
}
- if cmd.Flag("sort").Changed && !sortFields.Contains(listFlag.sort) {
+ if cmd.Flags().Changed("sort") && !sortFields.Contains(listFlag.sort) {
return fmt.Errorf("\"%s\" is not a valid field for sorting. Choose from: %s",
listFlag.sort, sortFields.String())
}
@@ -140,7 +140,7 @@ func images(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("format") && !report.HasTable(listFlag.format) {
listFlag.noHeading = true
}
- return writeTemplate(imgs)
+ return writeTemplate(cmd, imgs)
}
}
@@ -186,38 +186,31 @@ func writeJSON(images []imageReporter) error {
return nil
}
-func writeTemplate(imgs []imageReporter) error {
+func writeTemplate(cmd *cobra.Command, imgs []imageReporter) error {
hdrs := report.Headers(imageReporter{}, map[string]string{
"ID": "IMAGE ID",
"ReadOnly": "R/O",
})
- var format string
- if listFlag.format == "" {
- format = lsFormatFromFlags(listFlag)
- } else {
- format = report.NormalizeFormat(listFlag.format)
- format = report.EnforceRange(format)
- }
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
- tmpl, err := report.NewTemplate("list").Parse(format)
- if err != nil {
- return err
+ var err error
+ if cmd.Flags().Changed("format") {
+ rpt, err = rpt.Parse(report.OriginUser, cmd.Flag("format").Value.String())
+ } else {
+ rpt, err = rpt.Parse(report.OriginPodman, lsFormatFromFlags(listFlag))
}
-
- w, err := report.NewWriterDefault(os.Stdout)
if err != nil {
return err
}
- defer w.Flush()
- if !listFlag.noHeading {
- if err := tmpl.Execute(w, hdrs); err != nil {
+ if rpt.RenderHeaders && !listFlag.noHeading {
+ if err := rpt.Execute(hdrs); err != nil {
return err
}
}
-
- return tmpl.Execute(w, imgs)
+ return rpt.Execute(imgs)
}
func sortImages(imageS []*entities.ImageSummary) ([]imageReporter, error) {