summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2020-05-14 14:12:24 -0400
committerQi Wang <qiwan@redhat.com>2020-05-14 14:28:51 -0400
commit28ffe74e4441d96cb36abb58344824bfc4701c47 (patch)
tree72dfda68acbe15c07c91a856f83b327c45cc72da
parent7e9ed37c0997d6dd2d6fc6ed6476039ee954286c (diff)
downloadpodman-28ffe74e4441d96cb36abb58344824bfc4701c47.tar.gz
podman-28ffe74e4441d96cb36abb58344824bfc4701c47.tar.bz2
podman-28ffe74e4441d96cb36abb58344824bfc4701c47.zip
fix bug --format {{json.}} of events
Allow the `podman events --format` accept {{json.}} and complete small fix podman-events.1.md Signed-off-by: Qi Wang <qiwan@redhat.com>
-rw-r--r--cmd/podman/system/events.go4
-rw-r--r--docs/source/markdown/podman-events.1.md2
-rw-r--r--test/e2e/events_test.go14
3 files changed, 19 insertions, 1 deletions
diff --git a/cmd/podman/system/events.go b/cmd/podman/system/events.go
index 6aae62dc0..27e80138e 100644
--- a/cmd/podman/system/events.go
+++ b/cmd/podman/system/events.go
@@ -5,6 +5,7 @@ import (
"context"
"html/template"
"os"
+ "strings"
"github.com/containers/buildah/pkg/formats"
"github.com/containers/libpod/cmd/podman/registry"
@@ -54,6 +55,9 @@ func eventsCmd(cmd *cobra.Command, args []string) error {
eventsError error
tmpl *template.Template
)
+ if strings.Join(strings.Fields(eventFormat), "") == "{{json.}}" {
+ eventFormat = formats.JSONString
+ }
if eventFormat != formats.JSONString {
tmpl, err = template.New("events").Parse(eventFormat)
if err != nil {
diff --git a/docs/source/markdown/podman-events.1.md b/docs/source/markdown/podman-events.1.md
index bb1923574..a05047684 100644
--- a/docs/source/markdown/podman-events.1.md
+++ b/docs/source/markdown/podman-events.1.md
@@ -142,7 +142,7 @@ $ sudo podman events --since 5m
Show Podman events in JSON Lines format
```
-events --format json
+$ podman events --format json
{"ID":"683b0909d556a9c02fa8cd2b61c3531a965db42158627622d1a67b391964d519","Image":"localhost/myshdemo:latest","Name":"agitated_diffie","Status":"cleanup","Time":"2019-04-27T22:47:00.849932843-04:00","Type":"container"}
{"ID":"a0f8ab051bfd43f9c5141a8a2502139707e4b38d98ac0872e57c5315381e88ad","Image":"docker.io/library/alpine:latest","Name":"friendly_tereshkova","Status":"unmount","Time":"2019-04-28T13:43:38.063017276-04:00","Type":"container"}
```
diff --git a/test/e2e/events_test.go b/test/e2e/events_test.go
index 0636af74c..289f23b54 100644
--- a/test/e2e/events_test.go
+++ b/test/e2e/events_test.go
@@ -137,5 +137,19 @@ var _ = Describe("Podman events", func() {
_, exist := eventsMap["Status"]
Expect(exist).To(BeTrue())
Expect(test.ExitCode()).To(BeZero())
+
+ test = podmanTest.Podman([]string{"events", "--stream=false", "--format", "{{json.}}"})
+ test.WaitWithDefaultTimeout()
+ fmt.Println(test.OutputToStringArray())
+ jsonArr = test.OutputToStringArray()
+ Expect(len(jsonArr)).To(Not(BeZero()))
+ eventsMap = make(map[string]string)
+ err = json.Unmarshal([]byte(jsonArr[0]), &eventsMap)
+ if err != nil {
+ os.Exit(1)
+ }
+ _, exist = eventsMap["Status"]
+ Expect(exist).To(BeTrue())
+ Expect(test.ExitCode()).To(BeZero())
})
})