aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-07-29 14:10:59 -0400
committerDaniel J Walsh <dwalsh@redhat.com>2020-07-29 14:12:19 -0400
commit9917fc0f956c849ec2d52f3f873aa6eaa3f25e72 (patch)
tree4ca3031ca76b8664a29841e43b5e0271c14f933e /cmd/podman
parent7f38774ee7758e56cf31e87c81ae0bc9208d0ede (diff)
downloadpodman-9917fc0f956c849ec2d52f3f873aa6eaa3f25e72.tar.gz
podman-9917fc0f956c849ec2d52f3f873aa6eaa3f25e72.tar.bz2
podman-9917fc0f956c849ec2d52f3f873aa6eaa3f25e72.zip
Don't crash when giving bogus format commands
Currently if you give a bogus flag to --format it will crash the formatter. With this change we will get a nice error. podman images --format '{{ bogus }}' Error: template: list:1: function "bogus" not defined versus /bin/podman.old images --format '{{ bogus }}' panic: template: list:1: function "bogus" not defined goroutine 1 [running]: Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r--cmd/podman/images/history.go5
-rw-r--r--cmd/podman/images/list.go6
-rw-r--r--cmd/podman/system/connection/list.go6
3 files changed, 14 insertions, 3 deletions
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index ef5b4be26..f3a41f6b9 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -125,7 +125,10 @@ func history(cmd *cobra.Command, args []string) error {
}
format := hdr + "{{range . }}" + row + "{{end}}"
- tmpl := template.Must(template.New("report").Parse(format))
+ tmpl, err := template.New("report").Parse(format)
+ if err != nil {
+ return err
+ }
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
err = tmpl.Execute(w, hr)
if err != nil {
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 4552901f7..ee0f64d99 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -168,7 +168,11 @@ func writeTemplate(imgs []imageReporter) error {
}
}
format := hdr + "{{range . }}" + row + "{{end}}"
- tmpl := template.Must(template.New("list").Parse(format))
+ tmpl, err := template.New("list").Parse(format)
+ if err != nil {
+ return err
+ }
+ tmpl = template.Must(tmpl, nil)
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
defer w.Flush()
return tmpl.Execute(w, imgs)
diff --git a/cmd/podman/system/connection/list.go b/cmd/podman/system/connection/list.go
index 6d3d85d11..9010ec803 100644
--- a/cmd/podman/system/connection/list.go
+++ b/cmd/podman/system/connection/list.go
@@ -75,7 +75,11 @@ func list(_ *cobra.Command, _ []string) error {
// TODO: Allow user to override format
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end}}"
- tmpl := template.Must(template.New("connection").Parse(format))
+ tmpl, err := template.New("connection").Parse(format)
+ if err != nil {
+ return err
+ }
+
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
defer w.Flush()