summaryrefslogtreecommitdiff
path: root/cmd/podman/version.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-11-25 04:52:38 -0800
committerGitHub <noreply@github.com>2018-11-25 04:52:38 -0800
commite3ece3bb907145110408c54f70b839777b09da44 (patch)
tree3ebe3e39309aaf40245945e8eb99d46cd8f666ca /cmd/podman/version.go
parent5f8f15c797c07a53f12dda5499d0363ee74e5d1c (diff)
parent43c20d02006fb83d05414a2f868b1c0a4dd4346b (diff)
downloadpodman-e3ece3bb907145110408c54f70b839777b09da44.tar.gz
podman-e3ece3bb907145110408c54f70b839777b09da44.tar.bz2
podman-e3ece3bb907145110408c54f70b839777b09da44.zip
Merge pull request #1860 from TomasTomecek/version-add-format
implement --format for version command
Diffstat (limited to 'cmd/podman/version.go')
-rw-r--r--cmd/podman/version.go33
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",
+ },
+ }
+)