Skip to content

Commit

Permalink
support GO template {{ json . }}
Browse files Browse the repository at this point in the history
for podman version, we now support a GO template for json output.

fixes containers#2671

Signed-off-by: baude <[email protected]>
  • Loading branch information
baude committed Mar 18, 2019
1 parent ea54a1c commit 6aa8d14
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/podman/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strings"
"text/tabwriter"
"time"

Expand Down Expand Up @@ -43,6 +44,9 @@ func versionCmd(c *cliconfig.VersionValues) error {

versionOutputFormat := c.Format
if versionOutputFormat != "" {
if strings.Join(strings.Fields(versionOutputFormat), "") == "{{json.}}" {
versionOutputFormat = formats.JSONString
}
var out formats.Writer
switch versionOutputFormat {
case formats.JSONString:
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,24 @@ var _ = Describe("Podman version", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 2))
})

It("podman version --format json", func() {
session := podmanTest.Podman([]string{"version", "--format", "json"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})

It("podman version --format json", func() {
session := podmanTest.Podman([]string{"version", "--format", "{{ json .}}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})

It("podman version --format GO template", func() {
session := podmanTest.Podman([]string{"version", "--format", "{{ .Version }}"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
})

0 comments on commit 6aa8d14

Please sign in to comment.