mirror of https://github.com/containers/podman.git
podman auto-update: 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:
parent
0f39129551
commit
65e78d92c9
|
@ -4,7 +4,6 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/pkg/auth"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
|
@ -104,15 +103,15 @@ func reportsToOutput(allReports []*entities.AutoUpdateReport) []autoUpdateOutput
|
|||
}
|
||||
|
||||
func writeTemplate(allReports []*entities.AutoUpdateReport, inputFormat string) error {
|
||||
var format string
|
||||
var printHeader bool
|
||||
rpt := report.New(os.Stdout, "auto-update")
|
||||
defer rpt.Flush()
|
||||
|
||||
output := reportsToOutput(allReports)
|
||||
var err error
|
||||
switch inputFormat {
|
||||
case "":
|
||||
rows := []string{"{{.Unit}}", "{{.Container}}", "{{.Image}}", "{{.Policy}}", "{{.Updated}}"}
|
||||
format = "{{range . }}" + strings.Join(rows, "\t") + "\n{{end -}}"
|
||||
printHeader = true
|
||||
format := "{{range . }}\t{{.Unit}}\t{{.Container}}\t{{.Image}}\t{{.Policy}}\t{{.Updated}}\n{{end -}}"
|
||||
rpt, err = rpt.Parse(report.OriginPodman, format)
|
||||
case "json":
|
||||
prettyJSON, err := json.MarshalIndent(output, "", " ")
|
||||
if err != nil {
|
||||
|
@ -121,26 +120,17 @@ func writeTemplate(allReports []*entities.AutoUpdateReport, inputFormat string)
|
|||
fmt.Println(string(prettyJSON))
|
||||
return nil
|
||||
default:
|
||||
format = "{{range . }}" + inputFormat + "\n{{end -}}"
|
||||
rpt, err = rpt.Parse(report.OriginUser, inputFormat)
|
||||
}
|
||||
|
||||
tmpl, err := report.NewTemplate("auto-update").Parse(format)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
w, err := report.NewWriterDefault(os.Stdout)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer w.Flush()
|
||||
|
||||
if printHeader {
|
||||
if rpt.RenderHeaders {
|
||||
headers := report.Headers(autoUpdateOutput{}, nil)
|
||||
if err := tmpl.Execute(w, headers); err != nil {
|
||||
if err := rpt.Execute(headers); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return tmpl.Execute(w, output)
|
||||
return rpt.Execute(output)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue