diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-09-08 13:48:37 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-09-13 10:33:14 +0200 |
commit | 0c21dcf70c0a69f4614ca5d28c461f8ea50665dd (patch) | |
tree | 363f98e7277edd6938f7faa6f4f537607674ef7d | |
parent | e5389e98f78294f404ba611fc0d6a6396e8ca6f0 (diff) | |
download | podman-0c21dcf70c0a69f4614ca5d28c461f8ea50665dd.tar.gz podman-0c21dcf70c0a69f4614ca5d28c461f8ea50665dd.tar.bz2 podman-0c21dcf70c0a69f4614ca5d28c461f8ea50665dd.zip |
podman machine info: use report.Formatter over Template
Currently the podman command --format output code uses a mix of
report.Formatter and report.Template.
I patched report.Formatter to correctly handle newlines[1]. Since we
cannot fix this with report.Template we have to migrate all users to
report.Formatter. This ensures consistent behavior for all commands.
This change does not change the output.
[1] https://github.com/containers/common/pull/1146
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r-- | cmd/podman/machine/info.go | 12 | ||||
-rw-r--r-- | test/system/610-format.bats | 1 |
2 files changed, 7 insertions, 6 deletions
diff --git a/cmd/podman/machine/info.go b/cmd/podman/machine/info.go index 1151f9e86..9c7454379 100644 --- a/cmd/podman/machine/info.go +++ b/cmd/podman/machine/info.go @@ -5,7 +5,6 @@ package machine import ( "fmt" - "html/template" "os" "runtime" @@ -75,13 +74,16 @@ func info(cmd *cobra.Command, args []string) error { } fmt.Println(string(b)) case cmd.Flags().Changed("format"): - tmpl := template.New(cmd.Name()).Funcs(template.FuncMap(report.DefaultFuncs)) - inFormat = report.NormalizeFormat(inFormat) - tmpl, err := tmpl.Parse(inFormat) + rpt := report.New(os.Stdout, cmd.Name()) + defer rpt.Flush() + + // Use OriginUnknown so it does not add an extra range since it + // will only be called for a single element and not a slice. + rpt, err = rpt.Parse(report.OriginUnknown, inFormat) if err != nil { return err } - return tmpl.Execute(os.Stdout, info) + return rpt.Execute(info) default: b, err := yaml.Marshal(info) if err != nil { diff --git a/test/system/610-format.bats b/test/system/610-format.bats index 3781bc910..b0dbf2f48 100644 --- a/test/system/610-format.bats +++ b/test/system/610-format.bats @@ -20,7 +20,6 @@ function teardown() { # remove the entire lines, except for pod-inspect, just remove the SKIP # but leave "mypod") extra_args_table=" -machine info | SKIP version | SKIP history | $IMAGE |