mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
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>
This commit is contained in:
@ -3,7 +3,6 @@ package system
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/containers/common/pkg/completion"
|
"github.com/containers/common/pkg/completion"
|
||||||
"github.com/containers/common/pkg/report"
|
"github.com/containers/common/pkg/report"
|
||||||
@ -86,14 +85,16 @@ func info(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
fmt.Println(string(b))
|
fmt.Println(string(b))
|
||||||
case cmd.Flags().Changed("format"):
|
case cmd.Flags().Changed("format"):
|
||||||
// Cannot use report.New() as it enforces {{range .}} for OriginUser templates
|
rpt := report.New(os.Stdout, cmd.Name())
|
||||||
tmpl := template.New(cmd.Name()).Funcs(template.FuncMap(report.DefaultFuncs))
|
defer rpt.Flush()
|
||||||
inFormat = report.NormalizeFormat(inFormat)
|
|
||||||
tmpl, err := tmpl.Parse(inFormat)
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return tmpl.Execute(os.Stdout, info)
|
return rpt.Execute(info)
|
||||||
default:
|
default:
|
||||||
b, err := yaml.Marshal(info)
|
b, err := yaml.Marshal(info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,8 +20,6 @@ function teardown() {
|
|||||||
# remove the entire lines, except for pod-inspect, just remove the SKIP
|
# remove the entire lines, except for pod-inspect, just remove the SKIP
|
||||||
# but leave "mypod")
|
# but leave "mypod")
|
||||||
extra_args_table="
|
extra_args_table="
|
||||||
info | SKIP
|
|
||||||
system info | SKIP
|
|
||||||
machine info | SKIP
|
machine info | SKIP
|
||||||
version | SKIP
|
version | SKIP
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user