mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +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 {
|
func getMethodNames(f reflect.Value, prefix string) []string {
|
||||||
suggestions := make([]string, 0, f.NumMethod())
|
suggestions := make([]string, 0, f.NumMethod())
|
||||||
for j := 0; j < f.NumMethod(); j++ {
|
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) {
|
if strings.HasPrefix(fname, prefix) {
|
||||||
// add method name with closing braces
|
// add method name with closing braces
|
||||||
suggestions = append(suggestions, fname+"}}")
|
suggestions = append(suggestions, fname+"}}")
|
||||||
|
@ -37,6 +37,10 @@ func (c Car) internal() int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Car) TwoOut() (string, string) {
|
||||||
|
return "", ""
|
||||||
|
}
|
||||||
|
|
||||||
func TestAutocompleteFormat(t *testing.T) {
|
func TestAutocompleteFormat(t *testing.T) {
|
||||||
testStruct := struct {
|
testStruct := struct {
|
||||||
Name string
|
Name string
|
||||||
|
Reference in New Issue
Block a user