aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/images/history.go
diff options
context:
space:
mode:
authorJhon Honce <jhonce@redhat.com>2021-11-18 09:03:00 -0700
committerJhon Honce <jhonce@redhat.com>2021-12-02 09:07:27 -0700
commit61792de36ea2ea98f6e3aef3821d1b15beebf9e0 (patch)
treef2e73122b2cdb0323e1d38792eef44a625b85d10 /cmd/podman/images/history.go
parentfbcebcb46a2444ce078dee10d8d51555bee8f177 (diff)
downloadpodman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.tar.gz
podman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.tar.bz2
podman-61792de36ea2ea98f6e3aef3821d1b15beebf9e0.zip
Refactor podman image command output
Leverage new report.Formatter allowing better compatibility from podman command output. Follow on PR's will cover containers, etc. See #10974 Signed-off-by: Jhon Honce <jhonce@redhat.com>
Diffstat (limited to 'cmd/podman/images/history.go')
-rw-r--r--cmd/podman/images/history.go36
1 files changed, 15 insertions, 21 deletions
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index cc7b1b4eb..ac693a87b 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -1,7 +1,6 @@
package images
import (
- "context"
"fmt"
"os"
"strings"
@@ -79,7 +78,7 @@ func historyFlags(cmd *cobra.Command) {
}
func history(cmd *cobra.Command, args []string) error {
- results, err := registry.ImageEngine().History(context.Background(), args[0], entities.ImageHistoryOptions{})
+ results, err := registry.ImageEngine().History(registry.Context(), args[0], entities.ImageHistoryOptions{})
if err != nil {
return err
}
@@ -111,37 +110,32 @@ func history(cmd *cobra.Command, args []string) error {
hr = append(hr, historyReporter{l})
}
- hdrs := report.Headers(historyReporter{}, map[string]string{
- "CreatedBy": "CREATED BY",
- })
+ rpt := report.New(os.Stdout, cmd.Name())
+ defer rpt.Flush()
- // Defaults
- row := "{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n"
switch {
- case cmd.Flags().Changed("format"):
- row = report.NormalizeFormat(opts.format)
case opts.quiet:
- row = "{{.ID}}\n"
+ rpt, err = rpt.Parse(report.OriginUser, "{{range .}}{{.ID}}\n{{end -}}")
+ case cmd.Flags().Changed("format"):
+ rpt, err = rpt.Parse(report.OriginUser, cmd.Flag("format").Value.String())
+ default:
+ format := "{{range .}}{{.ID}}\t{{.Created}}\t{{.CreatedBy}}\t{{.Size}}\t{{.Comment}}\n{{end -}}"
+ rpt, err = rpt.Parse(report.OriginPodman, format)
}
- format := report.EnforceRange(row)
-
- tmpl, err := report.NewTemplate("history").Parse(format)
if err != nil {
return err
}
- w, err := report.NewWriterDefault(os.Stdout)
- if err != nil {
- return err
- }
- defer w.Flush()
+ if rpt.RenderHeaders {
+ hdrs := report.Headers(historyReporter{}, map[string]string{
+ "CreatedBy": "CREATED BY",
+ })
- if !opts.quiet && !cmd.Flags().Changed("format") {
- if err := tmpl.Execute(w, hdrs); err != nil {
+ if err := rpt.Execute(hdrs); err != nil {
return errors.Wrapf(err, "failed to write report column headers")
}
}
- return tmpl.Execute(w, hr)
+ return rpt.Execute(hr)
}
type historyReporter struct {