From 61792de36ea2ea98f6e3aef3821d1b15beebf9e0 Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Thu, 18 Nov 2021 09:03:00 -0700 Subject: 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 --- cmd/podman/networks/list.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'cmd/podman/networks') diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go index 124a17d5d..6f1a7742a 100644 --- a/cmd/podman/networks/list.go +++ b/cmd/podman/networks/list.go @@ -84,7 +84,7 @@ func networkList(cmd *cobra.Command, args []string) error { // table or other format output default: - err = templateOut(responses, cmd) + err = templateOut(cmd, responses) } return err @@ -105,7 +105,7 @@ func jsonOut(responses []types.Network) error { return nil } -func templateOut(responses []types.Network, cmd *cobra.Command) error { +func templateOut(cmd *cobra.Command, responses []types.Network) error { nlprs := make([]ListPrintReports, 0, len(responses)) for _, r := range responses { nlprs = append(nlprs, ListPrintReports{r}) @@ -120,14 +120,16 @@ func templateOut(responses []types.Network, cmd *cobra.Command) error { }) renderHeaders := report.HasTable(networkListOptions.Format) - var row, format string - if cmd.Flags().Changed("format") { + var row string + switch { + case cmd.Flags().Changed("format"): row = report.NormalizeFormat(networkListOptions.Format) - } else { // 'podman network ls' equivalent to 'podman network ls --format="table {{.ID}} {{.Name}} {{.Version}} {{.Plugins}}" ' - renderHeaders = true + default: + // 'podman network ls' equivalent to 'podman network ls --format="table {{.ID}} {{.Name}} {{.Version}} {{.Plugins}}" ' row = "{{.ID}}\t{{.Name}}\t{{.Driver}}\n" + renderHeaders = true } - format = report.EnforceRange(row) + format := report.EnforceRange(row) tmpl, err := report.NewTemplate("list").Parse(format) if err != nil { -- cgit v1.2.3-54-g00ecf