diff options
author | Jhon Honce <jhonce@redhat.com> | 2021-12-02 11:05:03 -0700 |
---|---|---|
committer | Jhon Honce <jhonce@redhat.com> | 2021-12-03 13:48:58 -0700 |
commit | 7d22cc88ef382033c59d09570d1525189e104eae (patch) | |
tree | 19c00abc3c22f7ae1a49e1a616864426fed5fe0a /cmd/podman/system/connection | |
parent | a50502dd3d8ef5c80d686824ba2023927825fd2c (diff) | |
download | podman-7d22cc88ef382033c59d09570d1525189e104eae.tar.gz podman-7d22cc88ef382033c59d09570d1525189e104eae.tar.bz2 podman-7d22cc88ef382033c59d09570d1525189e104eae.zip |
Refactor podman system to report.Formatter
[NO NEW TESTS NEEDED]
Support better compatibility output for podman system commands
* Format and content of output from podman version changed to
be more compatible
See #10974
Depends on containers/common#831
Signed-off-by: Jhon Honce <jhonce@redhat.com>
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) } |