mirror of https://github.com/containers/podman.git
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>
This commit is contained in:
parent
7f38774ee7
commit
9917fc0f95
|
|
@ -125,7 +125,10 @@ func history(cmd *cobra.Command, args []string) error {
|
||||||
}
|
}
|
||||||
format := hdr + "{{range . }}" + row + "{{end}}"
|
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)
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
err = tmpl.Execute(w, hr)
|
err = tmpl.Execute(w, hr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,11 @@ func writeTemplate(imgs []imageReporter) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
format := hdr + "{{range . }}" + row + "{{end}}"
|
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)
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
return tmpl.Execute(w, imgs)
|
return tmpl.Execute(w, imgs)
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,11 @@ func list(_ *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
// TODO: Allow user to override format
|
// TODO: Allow user to override format
|
||||||
format := "{{range . }}{{.Name}}\t{{.Identity}}\t{{.URI}}\n{{end}}"
|
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)
|
w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0)
|
||||||
defer w.Flush()
|
defer w.Flush()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue