summaryrefslogtreecommitdiff
path: root/cmd/podman/images
diff options
context:
space:
mode:
authorPaul Holzinger <paul.holzinger@web.de>2021-04-21 11:32:03 +0200
committerPaul Holzinger <paul.holzinger@web.de>2021-04-22 00:31:08 +0200
commitd81021ed265e3cdfe32cdd0082b139f796ff5bfa (patch)
tree5e3c0df7d77c2ecd6678cf0be1b05f4636b71e7c /cmd/podman/images
parent979f047d7392dafc2eb912ee7995140419690ee7 (diff)
downloadpodman-d81021ed265e3cdfe32cdd0082b139f796ff5bfa.tar.gz
podman-d81021ed265e3cdfe32cdd0082b139f796ff5bfa.tar.bz2
podman-d81021ed265e3cdfe32cdd0082b139f796ff5bfa.zip
Add go template shell completion for --format
The --format flags accepts go template strings. I use this often but I consistently forget the field names. This commit adds a way to provide shell completion for the --format flag. It works by automatically receiving the field names with the reflect package from the given struct. This requires almost no maintenance since this ensures that we always use the correct field names. This also works for nested structs. ``` $ podman ps --format "{{.P" {{.Pid}} {{.PIDNS}} {{.Pod}} {{.PodName}} {{.Ports}} ``` NOTE: This only works when you use quotes otherwise the shell does not provide completions. Also this does not work for fish at the moment. Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'cmd/podman/images')
-rw-r--r--cmd/podman/images/diff.go2
-rw-r--r--cmd/podman/images/history.go2
-rw-r--r--cmd/podman/images/inspect.go3
-rw-r--r--cmd/podman/images/list.go2
-rw-r--r--cmd/podman/images/mount.go2
5 files changed, 6 insertions, 5 deletions
diff --git a/cmd/podman/images/diff.go b/cmd/podman/images/diff.go
index 36b0d4e7a..7f4c3e83d 100644
--- a/cmd/podman/images/diff.go
+++ b/cmd/podman/images/diff.go
@@ -41,7 +41,7 @@ func diffFlags(flags *pflag.FlagSet) {
formatFlagName := "format"
flags.StringVar(&diffOpts.Format, formatFlagName, "", "Change the output format")
- _ = diffCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+ _ = diffCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(nil))
}
func diff(cmd *cobra.Command, args []string) error {
diff --git a/cmd/podman/images/history.go b/cmd/podman/images/history.go
index eaf56651f..16be0bb19 100644
--- a/cmd/podman/images/history.go
+++ b/cmd/podman/images/history.go
@@ -74,7 +74,7 @@ func historyFlags(cmd *cobra.Command) {
formatFlagName := "format"
flags.StringVar(&opts.format, formatFlagName, "", "Change the output to JSON or a Go template")
- _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+ _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(entities.ImageHistoryLayer{}))
flags.BoolVarP(&opts.human, "human", "H", true, "Display sizes and dates in human readable format")
flags.BoolVar(&opts.noTrunc, "no-trunc", false, "Do not truncate the output")
diff --git a/cmd/podman/images/inspect.go b/cmd/podman/images/inspect.go
index fb96286fa..ac3becaa6 100644
--- a/cmd/podman/images/inspect.go
+++ b/cmd/podman/images/inspect.go
@@ -5,6 +5,7 @@ import (
"github.com/containers/podman/v3/cmd/podman/inspect"
"github.com/containers/podman/v3/cmd/podman/registry"
"github.com/containers/podman/v3/pkg/domain/entities"
+ inspectTypes "github.com/containers/podman/v3/pkg/inspect"
"github.com/spf13/cobra"
)
@@ -34,7 +35,7 @@ func init() {
formatFlagName := "format"
flags.StringVarP(&inspectOpts.Format, formatFlagName, "f", "json", "Format the output to a Go template or json")
- _ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+ _ = inspectCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(inspectTypes.ImageData{}))
}
func inspectExec(cmd *cobra.Command, args []string) error {
diff --git a/cmd/podman/images/list.go b/cmd/podman/images/list.go
index 7a9a8a804..132af858b 100644
--- a/cmd/podman/images/list.go
+++ b/cmd/podman/images/list.go
@@ -83,7 +83,7 @@ func imageListFlagSet(cmd *cobra.Command) {
formatFlagName := "format"
flags.StringVar(&listFlag.format, formatFlagName, "", "Change the output format to JSON or a Go template")
- _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+ _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(entities.ImageSummary{}))
flags.BoolVar(&listFlag.digests, "digests", false, "Show digests")
flags.BoolVarP(&listFlag.noHeading, "noheading", "n", false, "Do not print column headings")
diff --git a/cmd/podman/images/mount.go b/cmd/podman/images/mount.go
index 79c97006d..a098aac63 100644
--- a/cmd/podman/images/mount.go
+++ b/cmd/podman/images/mount.go
@@ -51,7 +51,7 @@ func mountFlags(cmd *cobra.Command) {
formatFlagName := "format"
flags.StringVar(&mountOpts.Format, formatFlagName, "", "Print the mounted images in specified format (json)")
- _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteJSONFormat)
+ _ = cmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(nil))
}
func init() {