aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-09-08 12:48:28 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-09-13 10:33:14 +0200
commite5389e98f78294f404ba611fc0d6a6396e8ca6f0 (patch)
treebf53767ee89bb93f047a77dc68a2268940807115
parent1acebdda371ae84c4354de0b6eff22e9e70f31fe (diff)
downloadpodman-e5389e98f78294f404ba611fc0d6a6396e8ca6f0.tar.gz
podman-e5389e98f78294f404ba611fc0d6a6396e8ca6f0.tar.bz2
podman-e5389e98f78294f404ba611fc0d6a6396e8ca6f0.zip
podman 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/system/info.go13
-rw-r--r--test/system/610-format.bats2
2 files changed, 7 insertions, 8 deletions
diff --git a/cmd/podman/system/info.go b/cmd/podman/system/info.go
index 296fa4def..9613d5e56 100644
--- a/cmd/podman/system/info.go
+++ b/cmd/podman/system/info.go
@@ -3,7 +3,6 @@ package system
import (
"fmt"
"os"
- "text/template"
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
@@ -86,14 +85,16 @@ func info(cmd *cobra.Command, args []string) error {
}
fmt.Println(string(b))
case cmd.Flags().Changed("format"):
- // Cannot use report.New() as it enforces {{range .}} for OriginUser templates
- 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 77921b9a2..3781bc910 100644
--- a/test/system/610-format.bats
+++ b/test/system/610-format.bats
@@ -20,8 +20,6 @@ function teardown() {
# remove the entire lines, except for pod-inspect, just remove the SKIP
# but leave "mypod")
extra_args_table="
-info | SKIP
-system info | SKIP
machine info | SKIP
version | SKIP