diff options
Diffstat (limited to 'cmd/podman/images/list.go')
-rw-r--r-- | cmd/podman/images/list.go | 33 |
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) { |