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"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/containers/buildah/pkg/formats"
|
||||||
"github.com/containers/libpod/cmd/podman/registry"
|
"github.com/containers/libpod/cmd/podman/registry"
|
||||||
"github.com/containers/libpod/cmd/podman/validate"
|
"github.com/containers/libpod/cmd/podman/validate"
|
||||||
"github.com/containers/libpod/libpod/define"
|
"github.com/containers/libpod/libpod/define"
|
||||||
|
@ -51,6 +52,17 @@ func version(cmd *cobra.Command, args []string) error {
|
||||||
if !strings.HasSuffix(versionFormat, "\n") {
|
if !strings.HasSuffix(versionFormat, "\n") {
|
||||||
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)
|
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) {
|
func formatVersion(writer io.Writer, version *define.Version) {
|
||||||
fmt.Fprintf(writer, "Version:\t%s\n", version.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)
|
fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
|
||||||
if version.GitCommit != "" {
|
if version.GitCommit != "" {
|
||||||
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
fmt.Fprintf(writer, "Git Commit:\t%s\n", version.GitCommit)
|
||||||
|
|
|
@ -121,7 +121,7 @@ version:
|
||||||
GitCommit: c3678ce3289f4195f3f16802411e795c6a587c9f-dirty
|
GitCommit: c3678ce3289f4195f3f16802411e795c6a587c9f-dirty
|
||||||
GoVersion: go1.14.2
|
GoVersion: go1.14.2
|
||||||
OsArch: linux/amd64
|
OsArch: linux/amd64
|
||||||
RemoteAPIVersion: 1
|
APIVersion: 1
|
||||||
Version: 2.0.0
|
Version: 2.0.0
|
||||||
```
|
```
|
||||||
Run podman info with JSON formatted response:
|
Run podman info with JSON formatted response:
|
||||||
|
@ -228,7 +228,7 @@ Run podman info with JSON formatted response:
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"RemoteAPIVersion": 1,
|
"APIVersion": 1,
|
||||||
"Version": "2.0.0",
|
"Version": "2.0.0",
|
||||||
"GoVersion": "go1.14.2",
|
"GoVersion": "go1.14.2",
|
||||||
"GitCommit": "c3678ce3289f4195f3f16802411e795c6a587c9f-dirty",
|
"GitCommit": "c3678ce3289f4195f3f16802411e795c6a587c9f-dirty",
|
||||||
|
|
|
@ -25,17 +25,18 @@ Change output format to "json" or a Go template.
|
||||||
A sample output of the `version` command:
|
A sample output of the `version` command:
|
||||||
```
|
```
|
||||||
$ podman version
|
$ podman version
|
||||||
Version: 0.11.1
|
Version: 2.0.0
|
||||||
Go Version: go1.11
|
API Version: 1
|
||||||
Git Commit: "8967a1d691ed44896b81ad48c863033f23c65eb0-dirty"
|
Go Version: go1.14.2
|
||||||
Built: Thu Nov 8 22:35:40 2018
|
Git Commit: 4520664f63c3a7f9a80227715359e20069d95542
|
||||||
OS/Arch: linux/amd64
|
Built: Tue May 19 10:48:59 2020
|
||||||
|
OS/Arch: linux/amd64
|
||||||
```
|
```
|
||||||
|
|
||||||
Filtering out only the version:
|
Filtering out only the version:
|
||||||
```
|
```
|
||||||
$ podman version --format '{{.Client.Version}}'
|
$ podman version --format '{{.Client.Version}}'
|
||||||
1.6.3
|
2.0.0
|
||||||
```
|
```
|
||||||
|
|
||||||
## SEE ALSO
|
## SEE ALSO
|
||||||
|
|
|
@ -20,13 +20,13 @@ var (
|
||||||
|
|
||||||
// Version is an output struct for varlink
|
// Version is an output struct for varlink
|
||||||
type Version struct {
|
type Version struct {
|
||||||
RemoteAPIVersion int64
|
APIVersion int64
|
||||||
Version string
|
Version string
|
||||||
GoVersion string
|
GoVersion string
|
||||||
GitCommit string
|
GitCommit string
|
||||||
BuiltTime string
|
BuiltTime string
|
||||||
Built int64
|
Built int64
|
||||||
OsArch string
|
OsArch string
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetVersion returns a VersionOutput struct for varlink and podman
|
// GetVersion returns a VersionOutput struct for varlink and podman
|
||||||
|
@ -42,12 +42,12 @@ func GetVersion() (Version, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Version{
|
return Version{
|
||||||
RemoteAPIVersion: podmanVersion.RemoteAPIVersion,
|
APIVersion: podmanVersion.APIVersion,
|
||||||
Version: podmanVersion.Version,
|
Version: podmanVersion.Version,
|
||||||
GoVersion: runtime.Version(),
|
GoVersion: runtime.Version(),
|
||||||
GitCommit: gitCommit,
|
GitCommit: gitCommit,
|
||||||
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
BuiltTime: time.Unix(buildTime, 0).Format(time.ANSIC),
|
||||||
Built: buildTime,
|
Built: buildTime,
|
||||||
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
OsArch: runtime.GOOS + "/" + runtime.GOARCH,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,12 +112,12 @@ func Version(ctx context.Context) (*entities.SystemVersionReport, error) {
|
||||||
f, _ := strconv.ParseFloat(component.APIVersion, 64)
|
f, _ := strconv.ParseFloat(component.APIVersion, 64)
|
||||||
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
b, _ := time.Parse(time.RFC3339, component.BuildTime)
|
||||||
report.Server = &define.Version{
|
report.Server = &define.Version{
|
||||||
RemoteAPIVersion: int64(f),
|
APIVersion: int64(f),
|
||||||
Version: component.Version.Version,
|
Version: component.Version.Version,
|
||||||
GoVersion: component.GoVersion,
|
GoVersion: component.GoVersion,
|
||||||
GitCommit: component.GitCommit,
|
GitCommit: component.GitCommit,
|
||||||
Built: b.Unix(),
|
Built: b.Unix(),
|
||||||
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
OsArch: fmt.Sprintf("%s/%s", component.Os, component.Arch),
|
||||||
}
|
}
|
||||||
return &report, err
|
return &report, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ func (i *VarlinkAPI) GetVersion(call iopodman.VarlinkCall) error {
|
||||||
versionInfo.GitCommit,
|
versionInfo.GitCommit,
|
||||||
time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
|
time.Unix(versionInfo.Built, 0).Format(time.RFC3339),
|
||||||
versionInfo.OsArch,
|
versionInfo.OsArch,
|
||||||
versionInfo.RemoteAPIVersion,
|
versionInfo.APIVersion,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ function setup() {
|
||||||
|
|
||||||
is "${lines[0]}" "Version:[ ]\+[1-9][0-9.]\+" "Version line 1"
|
is "${lines[0]}" "Version:[ ]\+[1-9][0-9.]\+" "Version line 1"
|
||||||
is "$output" ".*Go Version: \+" "'Go Version' in output"
|
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.
|
// bumped.
|
||||||
const Version = "2.0.0-dev"
|
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
|
// client API. It is used to determine compatibility
|
||||||
// between a remote podman client and its backend
|
// between a remote podman client and its backend
|
||||||
const RemoteAPIVersion = 1
|
const APIVersion = 1
|
||||||
|
|
Loading…
Reference in New Issue