Skip to content

Commit

Permalink
podman info: use report.Formatter over Template
Browse files Browse the repository at this point in the history
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] containers/common#1146

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Sep 13, 2022
1 parent 1acebdd commit e5389e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 7 additions & 6 deletions cmd/podman/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package system
import (
"fmt"
"os"
"text/template"

"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions test/system/610-format.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5389e9

Please sign in to comment.