diff options
Diffstat (limited to 'cmd/podman/system/connection')
-rw-r--r-- | cmd/podman/system/connection/list.go | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go index 2710142a8..fbae1e4eb 100644 --- a/cmd/podman/system/connection/list.go +++ b/cmd/podman/system/connection/list.go @@ -53,13 +53,6 @@ func list(cmd *cobra.Command, _ []string) error { return err } - hdrs := []map[string]string{{ - "Identity": "Identity", - "Name": "Name", - "URI": "URI", - "Default": "Default", - }} - rows := make([]namedDestination, 0) for k, v := range cfg.Engine.ServiceDestinations { def := false @@ -82,35 +75,37 @@ func list(cmd *cobra.Command, _ []string) error { return rows[i].Name < rows[j].Name }) - var format string - switch { - case report.IsJSON(cmd.Flag("format").Value.String()): + rpt := report.New(os.Stdout, cmd.Name()) + defer rpt.Flush() + + if report.IsJSON(cmd.Flag("format").Value.String()) { buf, err := registry.JSONLibrary().MarshalIndent(rows, "", " ") if err == nil { fmt.Println(string(buf)) } return err - case cmd.Flags().Changed("format"): - format = report.NormalizeFormat(cmd.Flag("format").Value.String()) - default: - format = "{{.Name}}\t{{.URI}}\t{{.Identity}}\t{{.Default}}\n" } - format = report.EnforceRange(format) - tmpl, err := report.NewTemplate("list").Parse(format) - if err != nil { - return err + if cmd.Flag("format").Changed { + rpt, err = rpt.Parse(report.OriginUser, cmd.Flag("format").Value.String()) + } else { + rpt, err = rpt.Parse(report.OriginPodman, + "{{range .}}{{.Name}}\t{{.URI}}\t{{.Identity}}\t{{.Default}}\n{{end -}}") } - - w, err := report.NewWriterDefault(os.Stdout) if err != nil { return err } - defer w.Flush() - isTable := report.HasTable(cmd.Flag("format").Value.String()) - if !cmd.Flag("format").Changed || isTable { - _ = tmpl.Execute(w, hdrs) + if rpt.RenderHeaders { + err = rpt.Execute([]map[string]string{{ + "Default": "Default", + "Identity": "Identity", + "Name": "Name", + "URI": "URI", + }}) + if err != nil { + return err + } } - return tmpl.Execute(w, rows) + return rpt.Execute(rows) } |