aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/system/version.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/system/version.go')
-rw-r--r--cmd/podman/system/version.go77
1 files changed, 41 insertions, 36 deletions
diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go
index 87b806503..521bb8774 100644
--- a/cmd/podman/system/version.go
+++ b/cmd/podman/system/version.go
@@ -2,16 +2,15 @@ package system
import (
"fmt"
- "io"
"os"
"strings"
+ "text/template"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/cmd/podman/validate"
- "github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
)
@@ -53,54 +52,60 @@ func version(cmd *cobra.Command, args []string) error {
return nil
}
- w, err := report.NewWriterDefault(os.Stdout)
- if err != nil {
- return err
- }
- defer w.Flush()
+ if cmd.Flag("format").Changed {
+ // Cannot use report.New() as it enforces {{range .}} for OriginUser templates
+ tmpl := template.New(cmd.Name()).Funcs(template.FuncMap(report.DefaultFuncs))
- if cmd.Flags().Changed("format") {
- row := report.NormalizeFormat(versionFormat)
- tmpl, err := report.NewTemplate("version 2.0.0").Parse(row)
+ versionFormat = report.NormalizeFormat(versionFormat)
+ tmpl, err := tmpl.Parse(versionFormat)
if err != nil {
return err
}
- if err := tmpl.Execute(w, versions); err != nil {
+ if err := tmpl.Execute(os.Stdout, versions); err != nil {
// On Failure, assume user is using older version of podman version --format and check client
- row = strings.ReplaceAll(row, ".Server.", ".")
- tmpl, err := report.NewTemplate("version 1.0.0").Parse(row)
+ versionFormat = strings.ReplaceAll(versionFormat, ".Server.", ".")
+ tmpl, err := tmpl.Parse(versionFormat)
if err != nil {
return err
}
- if err := tmpl.Execute(w, versions.Client); err != nil {
+ if err := tmpl.Execute(os.Stdout, versions.Client); err != nil {
return err
}
}
return nil
}
- if versions.Server != nil {
- if _, err := fmt.Fprintf(w, "Client:\n"); err != nil {
- return err
- }
- formatVersion(w, versions.Client)
- if _, err := fmt.Fprintf(w, "\nServer:\n"); err != nil {
- return err
- }
- formatVersion(w, versions.Server)
- } else {
- formatVersion(w, versions.Client)
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
+ rpt, err = rpt.Parse(report.OriginPodman, versionTemplate)
+ if err != nil {
+ return err
}
- return nil
+ return rpt.Execute(versions)
}
-func formatVersion(w io.Writer, version *define.Version) {
- fmt.Fprintf(w, "Version:\t%s\n", version.Version)
- fmt.Fprintf(w, "API Version:\t%s\n", version.APIVersion)
- fmt.Fprintf(w, "Go Version:\t%s\n", version.GoVersion)
- if version.GitCommit != "" {
- fmt.Fprintf(w, "Git Commit:\t%s\n", version.GitCommit)
- }
- fmt.Fprintf(w, "Built:\t%s\n", version.BuiltTime)
- fmt.Fprintf(w, "OS/Arch:\t%s\n", version.OsArch)
-}
+const versionTemplate = `{{with .Client -}}
+Client:\tPodman Engine
+Version:\t{{.Version}}
+API Version:\t{{.APIVersion}}
+Go Version:\t{{.GoVersion}}
+{{if .GitCommit -}}
+ Git Commit:\t{{.GitCommit}}
+{{- end}}
+Built:\t{{.BuiltTime}}
+OS/Arch:\t{{.OsArch}}
+{{- end}}
+
+{{- if .Server }}{{with .Server}}
+
+Server:\tPodman Engine
+Version:\t{{.Version}}
+API Version:\t{{.APIVersion}}
+Go Version:\t{{.GoVersion}}
+{{if .GitCommit -}}
+ Git Commit:\t{{.GitCommit}}
+{{- end}}
+Built:\t{{.BuiltTime}}
+OS/Arch:\t{{.OsArch}}
+{{- end}}{{- end}}
+`