diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-05-27 09:59:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-27 09:59:25 -0400 |
commit | 89b4683cc4666f789ebc3d21453ef65e37775642 (patch) | |
tree | 52ab1e66783719993efacb5f1e365752fa191fc4 /cmd/podman/pods | |
parent | 9cb5c87284377507aafae8456ee8f00823954712 (diff) | |
parent | 1f8a78747aebf9c597f2bd93db5fc4c074286d38 (diff) | |
download | podman-89b4683cc4666f789ebc3d21453ef65e37775642.tar.gz podman-89b4683cc4666f789ebc3d21453ef65e37775642.tar.bz2 podman-89b4683cc4666f789ebc3d21453ef65e37775642.zip |
Merge pull request #6372 from boaz0/gh_6283
Add --format to pod inspect
Diffstat (limited to 'cmd/podman/pods')
-rw-r--r-- | cmd/podman/pods/inspect.go | 13 |
1 files changed, 8 insertions, 5 deletions
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() } |