podman secret inspect: 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, we can add a new test for the
newline bug when the common PR is vendored in.

[1] https://github.com/containers/common/pull/1146

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2022-09-07 14:43:52 +02:00
parent f5e13ded93
commit 377599f1f4
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
1 changed files with 4 additions and 9 deletions

View File

@ -47,20 +47,15 @@ func inspect(cmd *cobra.Command, args []string) error {
} }
if cmd.Flags().Changed("format") { if cmd.Flags().Changed("format") {
row := report.NormalizeFormat(format) rpt := report.New(os.Stdout, cmd.Name())
formatted := report.EnforceRange(row) defer rpt.Flush()
tmpl, err := report.NewTemplate("inspect").Parse(formatted) rpt, err := rpt.Parse(report.OriginUser, format)
if err != nil { if err != nil {
return err return err
} }
w, err := report.NewWriterDefault(os.Stdout) if err := rpt.Execute(inspected); err != nil {
if err != nil {
return err
}
defer w.Flush()
if err := tmpl.Execute(w, inspected); err != nil {
return err return err
} }
} else { } else {