mirror of
https://github.com/containers/podman.git
synced 2025-06-23 02:18:13 +08:00
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>
This commit is contained in:
@ -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+"}}")
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user