From 7b188f7b5b28ea04bcda1747f1869a50ac4b6f4a Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Tue, 19 May 2020 11:00:59 -0400 Subject: podman version --format ... was not working This patch fixes the podman --version --format command. Signed-off-by: Daniel J Walsh --- cmd/podman/system/version.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'cmd/podman/system/version.go') diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go index b7fa289a5..92a3225b6 100644 --- a/cmd/podman/system/version.go +++ b/cmd/podman/system/version.go @@ -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) -- cgit v1.2.3-54-g00ecf