From f128bff232a9d9ee14376af83e7f917d3c47ceb8 Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Thu, 8 Oct 2020 15:37:44 -0700 Subject: Restore --format table... Following commands: * systemd generate * networks inspect * pod stats * Fixed test where format was quoted and then quoted again * Fixed bug where output never printed '--' on missed reads * pod ps Signed-off-by: Jhon Honce --- cmd/podman/networks/inspect.go | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'cmd/podman/networks') diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go index c5872def7..c36125948 100644 --- a/cmd/podman/networks/inspect.go +++ b/cmd/podman/networks/inspect.go @@ -3,12 +3,13 @@ package network import ( "encoding/json" "fmt" - "io" "os" - "strings" + "text/tabwriter" "text/template" + "github.com/containers/podman/v2/cmd/podman/parse" "github.com/containers/podman/v2/cmd/podman/registry" + "github.com/containers/podman/v2/cmd/podman/report" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/spf13/cobra" ) @@ -39,31 +40,32 @@ func init() { flags.StringVarP(&networkInspectOptions.Format, "format", "f", "", "Pretty-print network to JSON or using a Go template") } -func networkInspect(cmd *cobra.Command, args []string) error { +func networkInspect(_ *cobra.Command, args []string) error { responses, err := registry.ContainerEngine().NetworkInspect(registry.Context(), args, entities.NetworkInspectOptions{}) if err != nil { return err } - b, err := json.MarshalIndent(responses, "", " ") - if err != nil { - return err - } - if strings.ToLower(networkInspectOptions.Format) == "json" || networkInspectOptions.Format == "" { - fmt.Println(string(b)) - } else { - var w io.Writer = os.Stdout - //There can be more than 1 in the inspect output. - format := "{{range . }}" + networkInspectOptions.Format + "{{end}}" - tmpl, err := template.New("inspectNetworks").Parse(format) + + switch { + case parse.MatchesJSONFormat(networkInspectOptions.Format) || networkInspectOptions.Format == "": + b, err := json.MarshalIndent(responses, "", " ") if err != nil { return err } - if err := tmpl.Execute(w, responses); err != nil { + fmt.Println(string(b)) + default: + row := report.NormalizeFormat(networkInspectOptions.Format) + // There can be more than 1 in the inspect output. + row = "{{range . }}" + row + "{{end}}" + tmpl, err := template.New("inspectNetworks").Parse(row) + if err != nil { return err } - if flusher, ok := w.(interface{ Flush() error }); ok { - return flusher.Flush() - } + + w := tabwriter.NewWriter(os.Stdout, 8, 2, 0, ' ', 0) + defer w.Flush() + + return tmpl.Execute(w, responses) } return nil } -- cgit v1.2.3-54-g00ecf