diff options
Diffstat (limited to 'cmd/podman/auto-update.go')
-rw-r--r-- | cmd/podman/auto-update.go | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/cmd/podman/auto-update.go b/cmd/podman/auto-update.go index 88ef0ec88..6a0446422 100644 --- a/cmd/podman/auto-update.go +++ b/cmd/podman/auto-update.go @@ -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) } |