mirror of https://github.com/containers/podman.git
implement --format for version command
Signed-off-by: Tomas Tomecek <ttomecek@redhat.com>
This commit is contained in:
parent
78604c3c39
commit
43c20d0200
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containers/libpod/cmd/podman/formats"
|
||||||
"github.com/containers/libpod/libpod"
|
"github.com/containers/libpod/libpod"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
|
@ -15,6 +16,19 @@ func versionCmd(c *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.Wrapf(err, "unable to determine version")
|
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("Version: ", output.Version)
|
||||||
fmt.Println("Go Version: ", output.GoVersion)
|
fmt.Println("Go Version: ", output.GoVersion)
|
||||||
if output.GitCommit != "" {
|
if output.GitCommit != "" {
|
||||||
|
@ -30,8 +44,17 @@ func versionCmd(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cli command to print out the full version of podman
|
// Cli command to print out the full version of podman
|
||||||
var versionCommand = cli.Command{
|
var (
|
||||||
Name: "version",
|
versionCommand = cli.Command{
|
||||||
Usage: "Display the PODMAN Version Information",
|
Name: "version",
|
||||||
Action: versionCmd,
|
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",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
|
@ -1906,11 +1906,16 @@ _podman_top() {
|
||||||
}
|
}
|
||||||
|
|
||||||
_podman_version() {
|
_podman_version() {
|
||||||
local options_with_args="
|
local boolean_options="
|
||||||
"
|
--help
|
||||||
local boolean_options="
|
-h
|
||||||
"
|
"
|
||||||
_complete_ "$options_with_args" "$boolean_options"
|
local options_with_args="
|
||||||
|
--format
|
||||||
|
"
|
||||||
|
local all_options="$options_with_args $boolean_options"
|
||||||
|
|
||||||
|
_complete_ "$options_with_args" "$boolean_options"
|
||||||
}
|
}
|
||||||
|
|
||||||
_podman_save() {
|
_podman_save() {
|
||||||
|
|
|
@ -16,8 +16,31 @@ OS, and Architecture.
|
||||||
|
|
||||||
Print usage statement
|
Print usage statement
|
||||||
|
|
||||||
|
**--format**
|
||||||
|
|
||||||
|
Change output format to "json" or a Go template.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
A sample output of the `version` command:
|
||||||
|
```
|
||||||
|
$ podman version
|
||||||
|
Version: 0.11.1
|
||||||
|
Go Version: go1.11
|
||||||
|
Git Commit: "8967a1d691ed44896b81ad48c863033f23c65eb0-dirty"
|
||||||
|
Built: Thu Nov 8 22:35:40 2018
|
||||||
|
OS/Arch: linux/amd64
|
||||||
|
```
|
||||||
|
|
||||||
|
Filtering out only the version:
|
||||||
|
```
|
||||||
|
$ podman version --format '{{.Version}}'
|
||||||
|
0.11.2
|
||||||
|
```
|
||||||
|
|
||||||
## SEE ALSO
|
## SEE ALSO
|
||||||
podman(1), crio(8)
|
podman(1), crio(8)
|
||||||
|
|
||||||
## HISTORY
|
## HISTORY
|
||||||
|
November 2018, Added --format flag by Tomas Tomecek <ttomecek@redhat.com>
|
||||||
July 2017, Originally compiled by Urvashi Mohnani <umohnani@redhat.com>
|
July 2017, Originally compiled by Urvashi Mohnani <umohnani@redhat.com>
|
||||||
|
|
Loading…
Reference in New Issue