podman version --format ... was not working
This patch fixes the podman --version --format command. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
17171aecf4
commit
7b188f7b5b
|
@ -7,6 +7,7 @@ import (
|
|||
"strings"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/containers/buildah/pkg/formats"
|
||||
"github.com/containers/libpod/cmd/podman/registry"
|
||||
"github.com/containers/libpod/cmd/podman/validate"
|
||||
"github.com/containers/libpod/libpod/define"
|
||||
|
@ -51,6 +52,17 @@ func version(cmd *cobra.Command, args []string) error {
|
|||
if !strings.HasSuffix(versionFormat, "\n") {
|
||||
versionFormat += "\n"
|
||||
}
|
||||
out := formats.StdoutTemplate{Output: versions, Template: versionFormat}
|
||||
err := out.Out()
|
||||
if err != nil {
|
||||
// On Failure, assume user is using older version of podman version --format and check client
|
||||
versionFormat = strings.Replace(versionFormat, ".Server.", ".", 1)
|
||||
out = formats.StdoutTemplate{Output: versions.Client, Template: versionFormat}
|
||||
if err1 := out.Out(); err1 != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
|
||||
|
@ -73,7 +85,7 @@ func version(cmd *cobra.Command, args []string) error {
|
|||
|
||||
func formatVersion(writer io.Writer, version *define.Version) {
|
||||
fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
|
||||
fmt.Fprintf(writer, "RemoteAPI Version:\t%d\n", version.RemoteAPIVersion)
|
||||
fmt.Fprintf(writer, "API Version:\t%d\n", version.APIVersion)
|
||||
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
||||
if version.GitCommit != "" {
|
||||
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
||||
|
|
|
@ -121,7 +121,7 @@ version:
|
|||
GitCommit: c3678ce3289f4195f3f16802411e795c6a587c9f-dirty
|
||||
GoVersion: go1.14.2
|
||||
OsArch: linux/amd64
|
||||
RemoteAPIVersion: 1
|
||||
APIVersion: 1
|
||||
Version: 2.0.0
|
||||
```
|
||||
Run podman info with JSON formatted response:
|
||||
|
@ -228,7 +228,7 @@ Run podman info with JSON formatted response:
|
|||
]
|
||||
},
|
||||
"version": {
|
||||
"RemoteAPIVersion": 1,
|
||||
"APIVersion": 1,
|
||||
"Version": "2.0.0",
|
||||
"GoVersion": "go1.14.2",
|
||||
"GitCommit": "c3678ce3289f4195f3f16802411e795c6a587c9f-dirty",
|
||||
|
|
|
@ -25,17 +25,18 @@ Change output format to "json" or a Go template.
|
|||
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
|
||||
Version: 2.0.0
|
||||
API Version: 1
|
||||
Go Version: go1.14.2
|
||||
Git Commit: 4520664f63c3a7f9a80227715359e20069d95542
|
||||
Built: Tue May 19 10:48:59 2020
|
||||
OS/Arch: linux/amd64
|
||||
```
|
||||
|
||||
Filtering out only the version:
|
||||
```
|
||||
$ podman version --format '{{.Client.Version}}'
|
||||
1.6.3
|
||||
2.0.0
|
||||
```
|
||||
|
||||
## SEE ALSO
|
||||
|
|
|
@ -20,13 +20,13 @@ var (
|
|||
|
||||
// Version is an output struct for varlink
|
||||
type Version struct {
|
||||
RemoteAPIVersion int64
|
||||
Version string
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
BuiltTime string
|
||||
Built int64
|
||||
OsArch string
|
||||
APIVersion int64
|
||||
Version string
|
||||
GoVersion string
|
||||
GitCommit string
|
||||
BuiltTime string
|
||||
Built int64
|
||||
OsArch string
|
||||
}
|
||||
|
||||
// GetVersion returns a VersionOutput struct for varlink and podman
|
||||
|
@ -42,12 +42,12 @@ func GetVersion() (Version, error) {
|
|||
}
|
||||
}
|
||||
return Version{
|
||||
RemoteAPIVersion: podmanVersion.RemoteAPIVersion,
|
||||
Version: podmanVersion.Version,
|
||||
GoVersion: runtime.Version(),
|
||||
GitCommit: gitCommit,
|
||||
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
||||
Built: buildTime,
|
||||
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
||||
APIVersion: podmanVersion.APIVersion,
|
||||
Version: podmanVersion.Version,
|
||||
GoVersion: runtime.Version(),
|
||||
GitCommit: gitCommit,
|
||||
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
||||
Built: buildTime,
|
||||
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -112,12 +112,12 @@ func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
|||
f, _ := strconv.ParseFloat(component.APIVersion, 64)
|
||||
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
||||
report.Server = &define.Version{
|
||||
RemoteAPIVersion: int64(f),
|
||||
Version: component.Version.Version,
|
||||
GoVersion: component.GoVersion,
|
||||
GitCommit: component.GitCommit,
|
||||
Built: b.Unix(),
|
||||
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
||||
APIVersion: int64(f),
|
||||
Version: component.Version.Version,
|
||||
GoVersion: component.GoVersion,
|
||||
GitCommit: component.GitCommit,
|
||||
Built: b.Unix(),
|
||||
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
||||
}
|
||||
return &report, err
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ func (i *VarlinkAPI) GetVersion(call iopodman.VarlinkCall) error {
|
|||
versionInfo.GitCommit,
|
||||
time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
|
||||
versionInfo.OsArch,
|
||||
versionInfo.RemoteAPIVersion,
|
||||
versionInfo.APIVersion,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ function setup() {
|
|||
|
||||
is "${lines[0]}" "Version:[ ]\+[1-9][0-9.]\+" "Version line 1"
|
||||
is "$output" ".*Go Version: \+" "'Go Version' in output"
|
||||
is "$output" ".*RemoteAPI Version: \+" "API version in output"
|
||||
is "$output" ".*API Version: \+" "API version in output"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ package version
|
|||
// bumped.
|
||||
const Version = "2.0.0-dev"
|
||||
|
||||
// RemoteAPIVersion is the version for the remote
|
||||
// APIVersion is the version for the remote
|
||||
// client API. It is used to determine compatibility
|
||||
// between a remote podman client and its backend
|
||||
const RemoteAPIVersion = 1
|
||||
const APIVersion = 1
|
||||
|
|
Loading…
Reference in New Issue