diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-10-30 17:00:22 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-30 17:00:22 +0100 |
commit | e632f3f2588d00184a50a7328d54a31ccf973708 (patch) | |
tree | e7fb78c6ae6c81a77aac78015e7a0421de6d552c /cmd/podman/images/search.go | |
parent | 6b5a94cf2831df0633cc03a28f432177c0ee1d7b (diff) | |
parent | d60a0ddcc1784b2dd807cc8e4d4f3deb0c074171 (diff) | |
download | podman-e632f3f2588d00184a50a7328d54a31ccf973708.tar.gz podman-e632f3f2588d00184a50a7328d54a31ccf973708.tar.bz2 podman-e632f3f2588d00184a50a7328d54a31ccf973708.zip |
Merge pull request #8187 from jwhonce/wip/table
Restore --format table header support
Diffstat (limited to 'cmd/podman/images/search.go')
-rw-r--r-- | cmd/podman/images/search.go | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/cmd/podman/images/search.go b/cmd/podman/images/search.go index b1a1442a6..66256aaa0 100644 --- a/cmd/podman/images/search.go +++ b/cmd/podman/images/search.go @@ -8,6 +8,7 @@ import ( "github.com/containers/common/pkg/auth" "github.com/containers/common/pkg/report" "github.com/containers/image/v5/types" + "github.com/containers/podman/v2/cmd/podman/parse" "github.com/containers/podman/v2/cmd/podman/registry" "github.com/containers/podman/v2/pkg/domain/entities" "github.com/pkg/errors" @@ -130,26 +131,30 @@ func imageSearch(cmd *cobra.Command, args []string) error { } hdrs := report.Headers(entities.ImageSearchReport{}, nil) - row := "{{.Index}}\t{{.Name}}\t{{.Description}}\t{{.Stars}}\t{{.Official}}\t{{.Automated}}\n" - if searchOptions.ListTags { + renderHeaders := true + var row string + switch { + case searchOptions.ListTags: if len(searchOptions.Filters) != 0 { return errors.Errorf("filters are not applicable to list tags result") } row = "{{.Name}}\t{{.Tag}}\n" - } - if cmd.Flags().Changed("format") { + case cmd.Flags().Changed("format"): + renderHeaders = parse.HasTable(searchOptions.Format) row = report.NormalizeFormat(searchOptions.Format) + default: + row = "{{.Index}}\t{{.Name}}\t{{.Description}}\t{{.Stars}}\t{{.Official}}\t{{.Automated}}\n" } - row = "{{range .}}" + row + "{{end}}" + format := parse.EnforceRange(row) - tmpl, err := template.New("search").Parse(row) + tmpl, err := template.New("search").Parse(format) if err != nil { return err } w := tabwriter.NewWriter(os.Stdout, 8, 2, 2, ' ', 0) defer w.Flush() - if !cmd.Flags().Changed("format") { + if renderHeaders { if err := tmpl.Execute(w, hdrs); err != nil { return errors.Wrapf(err, "failed to write search column headers") } |