diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-28 15:06:00 +0200 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2022-05-03 13:41:40 -0400 |
commit | a9deb5c676cb9c37adb3bdc5cb25dd5e41ea19b6 (patch) | |
tree | 10accfe86448f3034164703947a1fe615664df5e /cmd/podman/common/completion.go | |
parent | 835b89c6041261c6181e5c73b6aa80d7c89eb2ac (diff) | |
download | podman-a9deb5c676cb9c37adb3bdc5cb25dd5e41ea19b6.tar.gz podman-a9deb5c676cb9c37adb3bdc5cb25dd5e41ea19b6.tar.bz2 podman-a9deb5c676cb9c37adb3bdc5cb25dd5e41ea19b6.zip |
shell completion --format: use anonymous struct field once
We should not include the anonymous twice in the suggestions.
one example is `podman network ls --format {{.` it will also show
`{{.Network` but since Network is the actual struct all fields are
already shown so there is no need for it to be suggested.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common/completion.go')
-rw-r--r-- | cmd/podman/common/completion.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index 6f13eb5a2..ddf922b2a 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -1056,13 +1056,12 @@ func getStructFields(f reflect.Value, prefix string) []string { if kind == reflect.Struct { suffix = "." } - if strings.HasPrefix(fname, prefix) { - // add field name with suffix - suggestions = append(suggestions, fname+suffix) - } // if field is anonymous add the child fields as well if field.Anonymous { suggestions = append(suggestions, getStructFields(f.Field(j), prefix)...) + } else if strings.HasPrefix(fname, prefix) { + // add field name with suffix + suggestions = append(suggestions, fname+suffix) } } |