diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/containers/stats.go | 9 | ||||
-rw-r--r-- | cmd/podman/pods/inspect.go | 13 |
2 files changed, 16 insertions, 6 deletions
diff --git a/cmd/podman/containers/stats.go b/cmd/podman/containers/stats.go index 5b7f52cc7..c61b161e4 100644 --- a/cmd/podman/containers/stats.go +++ b/cmd/podman/containers/stats.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strings" + "sync" "text/tabwriter" "text/template" @@ -111,14 +112,20 @@ func stats(cmd *cobra.Command, args []string) error { } } statsOptions.StatChan = make(chan []*define.ContainerStats, 1) + wg := sync.WaitGroup{} + wg.Add(1) go func() { for reports := range statsOptions.StatChan { if err := outputStats(reports); err != nil { logrus.Error(err) } } + wg.Done() + }() - return registry.ContainerEngine().ContainerStats(registry.Context(), args, statsOptions) + err := registry.ContainerEngine().ContainerStats(registry.Context(), args, statsOptions) + wg.Wait() + return err } func outputStats(reports []*define.ContainerStats) error { diff --git a/cmd/podman/pods/inspect.go b/cmd/podman/pods/inspect.go index 1e333247b..34c07c11b 100644 --- a/cmd/podman/pods/inspect.go +++ b/cmd/podman/pods/inspect.go @@ -4,6 +4,7 @@ import ( "context" "fmt" + "github.com/containers/buildah/pkg/formats" "github.com/containers/libpod/cmd/podman/registry" "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" @@ -36,6 +37,7 @@ func init() { }) flags := inspectCmd.Flags() flags.BoolVarP(&inspectOptions.Latest, "latest", "l", false, "Act on the latest pod podman is aware of") + flags.StringVarP(&inspectOptions.Format, "format", "f", "json", "Format the output to a Go template or json") if registry.IsRemote() { _ = flags.MarkHidden("latest") } @@ -54,10 +56,11 @@ func inspect(cmd *cobra.Command, args []string) error { if err != nil { return err } - b, err := json.MarshalIndent(responses, "", " ") - if err != nil { - return err + var data interface{} = responses + var out formats.Writer = formats.JSONStruct{Output: data} + if inspectOptions.Format != "json" { + out = formats.StdoutTemplate{Output: data, Template: inspectOptions.Format} } - fmt.Println(string(b)) - return nil + + return out.Out() } |