diff options
author | Tomas Tomecek <ttomecek@redhat.com> | 2018-11-23 22:25:45 +0100 |
---|---|---|
committer | Tomas Tomecek <ttomecek@redhat.com> | 2018-11-25 12:42:05 +0100 |
commit | 43c20d02006fb83d05414a2f868b1c0a4dd4346b (patch) | |
tree | 9948a7c6019d8f1cd697609c986664606ce0b308 /cmd/podman | |
parent | 78604c3c397068f70ccb5e8b4be4b9229e2072fb (diff) | |
download | podman-43c20d02006fb83d05414a2f868b1c0a4dd4346b.tar.gz podman-43c20d02006fb83d05414a2f868b1c0a4dd4346b.tar.bz2 podman-43c20d02006fb83d05414a2f868b1c0a4dd4346b.zip |
implement --format for version command
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/version.go | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/cmd/podman/version.go b/cmd/podman/version.go index d80f24a14..d81deb696 100644 --- a/cmd/podman/version.go +++ b/cmd/podman/version.go @@ -4,6 +4,7 @@ import ( "fmt" "time" + "github.com/containers/libpod/cmd/podman/formats" "github.com/containers/libpod/libpod" "github.com/pkg/errors" "github.com/urfave/cli" @@ -15,6 +16,19 @@ func versionCmd(c *cli.Context) error { if err != nil { errors.Wrapf(err, "unable to determine version") } + + versionOutputFormat := c.String("format") + if versionOutputFormat != "" { + var out formats.Writer + switch versionOutputFormat { + case formats.JSONString: + out = formats.JSONStruct{Output: output} + default: + out = formats.StdoutTemplate{Output: output, Template: versionOutputFormat} + } + formats.Writer(out).Out() + return nil + } fmt.Println("Version: ", output.Version) fmt.Println("Go Version: ", output.GoVersion) if output.GitCommit != "" { @@ -30,8 +44,17 @@ func versionCmd(c *cli.Context) error { } // Cli command to print out the full version of podman -var versionCommand = cli.Command{ - Name: "version", - Usage: "Display the PODMAN Version Information", - Action: versionCmd, -} +var ( + versionCommand = cli.Command{ + Name: "version", + Usage: "Display the Podman Version Information", + Action: versionCmd, + Flags: versionFlags, + } + versionFlags = []cli.Flag{ + cli.StringFlag{ + Name: "format", + Usage: "Change the output format to JSON or a Go template", + }, + } +) |