summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-01 03:23:29 +0100
committerGitHub <noreply@github.com>2019-02-01 03:23:29 +0100
commite133834f6d60310ecd6cbd67b58f891f29b25e10 (patch)
treead2e81dd1262470d5614966ee176632525219457
parent82550ede36dab0689914c3c1b6de44b55f0d22f8 (diff)
parentca53122338168c867e75de0ce832d80ac7f27428 (diff)
downloadpodman-e133834f6d60310ecd6cbd67b58f891f29b25e10.tar.gz
podman-e133834f6d60310ecd6cbd67b58f891f29b25e10.tar.bz2
podman-e133834f6d60310ecd6cbd67b58f891f29b25e10.zip
Merge pull request #2232 from baude/pstable
Fix regression in ps with custom format
-rw-r--r--cmd/podman/images.go7
-rw-r--r--cmd/podman/ps.go41
-rw-r--r--test/e2e/ps_test.go7
3 files changed, 41 insertions, 14 deletions
diff --git a/cmd/podman/images.go b/cmd/podman/images.go
index 031f06618..d4f405975 100644
--- a/cmd/podman/images.go
+++ b/cmd/podman/images.go
@@ -188,13 +188,6 @@ func imagesCmd(c *cli.Context) error {
}
opts.outputformat = opts.setOutputFormat()
- /*
- podman does not implement --all for images
-
- intermediate images are only generated during the build process. they are
- children to the image once built. until buildah supports caching builds,
- it will not generate these intermediate images.
- */
images, err := runtime.GetImages()
if err != nil {
return errors.Wrapf(err, "unable to get images")
diff --git a/cmd/podman/ps.go b/cmd/podman/ps.go
index 0ad3f4c73..1708c671c 100644
--- a/cmd/podman/ps.go
+++ b/cmd/podman/ps.go
@@ -606,19 +606,50 @@ func portsToString(ports []ocicni.PortMapping) string {
}
func printFormat(format string, containers []shared.PsContainerOutput) error {
- out := template.New("output")
- out, err := out.Parse(format + "\n")
+ // return immediately if no containers are present
+ if len(containers) == 0 {
+ return nil
+ }
+
+ // Use a tabwriter to align column format
+ w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
+
+ // Make a map of the field names for the headers
+ headerNames := make(map[string]string)
+ v := reflect.ValueOf(containers[0])
+ t := v.Type()
+ for i := 0; i < t.NumField(); i++ {
+ headerNames[t.Field(i).Name] = t.Field(i).Name
+ }
+
+ // Spit out the header if "table" is present in the format
+ if strings.HasPrefix(format, "table") {
+ hformat := strings.Replace(strings.TrimSpace(format[5:]), " ", "\t", -1)
+ format = hformat
+ headerTmpl, err := template.New("header").Parse(hformat)
+ if err != nil {
+ return err
+ }
+ if err := headerTmpl.Execute(w, headerNames); err != nil {
+ return err
+ }
+ fmt.Fprintln(w, "")
+ }
+ // Spit out the data rows now
+ dataTmpl, err := template.New("data").Parse(format)
if err != nil {
return err
}
+
for _, container := range containers {
- if err := out.Execute(os.Stdout, container); err != nil {
+ if err := dataTmpl.Execute(w, container); err != nil {
return err
}
-
+ fmt.Fprintln(w, "")
}
- return nil
+ // Flush the writer
+ return w.Flush()
}
func dumpJSON(containers []shared.PsContainerOutput) error {
diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go
index bff2427d5..9b1c55bb4 100644
--- a/test/e2e/ps_test.go
+++ b/test/e2e/ps_test.go
@@ -7,6 +7,7 @@ import (
"os"
"regexp"
"sort"
+ "strings"
. "github.com/containers/libpod/test/utils"
"github.com/docker/go-units"
@@ -148,10 +149,12 @@ var _ = Describe("Podman ps", func() {
_, ec, _ := podmanTest.RunLsContainer("test1")
Expect(ec).To(Equal(0))
- result := podmanTest.Podman([]string{"ps", "-a", "--format", "\"table {{.ID}} {{.Image}} {{.Labels}}\""})
+ result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.ID}} {{.Image}} {{.Labels}}"})
result.WaitWithDefaultTimeout()
+ Expect(strings.Contains(result.OutputToStringArray()[0], "table")).To(BeFalse())
+ Expect(strings.Contains(result.OutputToStringArray()[0], "ID")).To(BeTrue())
+ Expect(strings.Contains(result.OutputToStringArray()[1], "alpine:latest")).To(BeTrue())
Expect(result.ExitCode()).To(Equal(0))
- Expect(result.IsJSONOutputValid()).To(BeTrue())
})
It("podman ps ancestor filter flag", func() {