summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-16 15:10:58 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-18 18:24:42 +0200
commit11ff5ffd3b0acba02991b0879a1b8493ea0f3bc9 (patch)
tree2b92dc76aa3ad218314309ad337677a46eec0a9f /cmd/podman/common
parenteeeb88a667141380b843d92eb4478553b2256f17 (diff)
downloadpodman-11ff5ffd3b0acba02991b0879a1b8493ea0f3bc9.tar.gz
podman-11ff5ffd3b0acba02991b0879a1b8493ea0f3bc9.tar.bz2
podman-11ff5ffd3b0acba02991b0879a1b8493ea0f3bc9.zip
shell completion --format: only show usable methods
In a template you cann call function that are defined on a type, however this is only useful if they return one value. If it returns more than one the template cannot know what value it has to display. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go7
-rw-r--r--cmd/podman/common/completion_test.go4
2 files changed, 10 insertions, 1 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 0db9f7351..3c614c0e1 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -1084,7 +1084,12 @@ func getStructFields(f reflect.Value, prefix string) []string {
func getMethodNames(f reflect.Value, prefix string) []string {
suggestions := make([]string, 0, f.NumMethod())
for j := 0; j < f.NumMethod(); j++ {
- fname := f.Type().Method(j).Name
+ method := f.Type().Method(j)
+ // in a template we can only run functions with one return value
+ if method.Func.Type().NumOut() != 1 {
+ continue
+ }
+ fname := method.Name
if strings.HasPrefix(fname, prefix) {
// add method name with closing braces
suggestions = append(suggestions, fname+"}}")
diff --git a/cmd/podman/common/completion_test.go b/cmd/podman/common/completion_test.go
index c9e189961..63b99501f 100644
--- a/cmd/podman/common/completion_test.go
+++ b/cmd/podman/common/completion_test.go
@@ -37,6 +37,10 @@ func (c Car) internal() int {
return 0
}
+func (c Car) TwoOut() (string, string) {
+ return "", ""
+}
+
func TestAutocompleteFormat(t *testing.T) {
testStruct := struct {
Name string