summaryrefslogtreecommitdiff
path: root/cmd/podman/system/version.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2020-10-09 09:13:22 -0700
committerJhon Honce <jhonce@redhat.com>2020-10-13 17:28:45 -0700
commiteb4a746efcb9e76e29942461b97da797fd67109f (patch)
tree980663ba01f79bd107980fd0c3205fe833503a41 /cmd/podman/system/version.go
parent7ad631b819d991559ba20e4728a6803a2546158f (diff)
downloadpodman-eb4a746efcb9e76e29942461b97da797fd67109f.tar.gz
podman-eb4a746efcb9e76e29942461b97da797fd67109f.tar.bz2
podman-eb4a746efcb9e76e29942461b97da797fd67109f.zip
Restore --format table support
* system df * events * fix error handling from go routine * update tests to use gomega matchers for better error messages * system info * version * volume inspect Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/system/version.go')
-rw-r--r--cmd/podman/system/version.go50
1 files changed, 29 insertions, 21 deletions
diff --git a/cmd/podman/system/version.go b/cmd/podman/system/version.go
index 9da7da54a..4f47c5fba 100644
--- a/cmd/podman/system/version.go
+++ b/cmd/podman/system/version.go
@@ -6,10 +6,11 @@ import (
"os"
"strings"
"text/tabwriter"
+ "text/template"
- "github.com/containers/buildah/pkg/formats"
"github.com/containers/podman/v2/cmd/podman/parse"
"github.com/containers/podman/v2/cmd/podman/registry"
+ "github.com/containers/podman/v2/cmd/podman/report"
"github.com/containers/podman/v2/cmd/podman/validate"
"github.com/containers/podman/v2/libpod/define"
"github.com/containers/podman/v2/pkg/domain/entities"
@@ -41,31 +42,38 @@ func version(cmd *cobra.Command, args []string) error {
return err
}
- switch {
- case parse.MatchesJSONFormat(versionFormat):
+ if parse.MatchesJSONFormat(versionFormat) {
s, err := json.MarshalToString(versions)
if err != nil {
return err
}
- _, err = io.WriteString(os.Stdout, s+"\n")
- return err
- case cmd.Flag("format").Changed:
- out := formats.StdoutTemplate{Output: versions, Template: versionFormat}
- err := out.Out()
+ fmt.Println(s)
+ return nil
+ }
+
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
+ defer w.Flush()
+
+ if cmd.Flag("format").Changed {
+ row := report.NormalizeFormat(versionFormat)
+ tmpl, err := template.New("version 2.0.0").Parse(row)
if err != nil {
+ return err
+ }
+ if err := tmpl.Execute(w, versions); 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 {
+ row = strings.Replace(row, ".Server.", ".", 1)
+ tmpl, err := template.New("version 1.0.0").Parse(row)
+ if err != nil {
+ return err
+ }
+ if err := tmpl.Execute(w, versions.Client); err != nil {
return err
}
}
return nil
}
- w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
- defer w.Flush()
-
if versions.Server != nil {
if _, err := fmt.Fprintf(w, "Client:\n"); err != nil {
return err
@@ -81,13 +89,13 @@ func version(cmd *cobra.Command, args []string) error {
return nil
}
-func formatVersion(writer io.Writer, version *define.Version) {
- fmt.Fprintf(writer, "Version:\t%s\n", version.Version)
- fmt.Fprintf(writer, "API Version:\t%s\n", version.APIVersion)
- fmt.Fprintf(writer, "Go Version:\t%s\n", version.GoVersion)
+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(writer, "Git Commit:\t%s\n", version.GitCommit)
+ fmt.Fprintf(w, "Git Commit:\t%s\n", version.GitCommit)
}
- fmt.Fprintf(writer, "Built:\t%s\n", version.BuiltTime)
- fmt.Fprintf(writer, "OS/Arch:\t%s\n", version.OsArch)
+ fmt.Fprintf(w, "Built:\t%s\n", version.BuiltTime)
+ fmt.Fprintf(w, "OS/Arch:\t%s\n", version.OsArch)
}