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>
This commit is contained in:
parent
8be9781586
commit
cb9a45630f
|
@ -1056,13 +1056,12 @@ func getStructFields(f reflect.Value, prefix string) []string {
|
||||||
if kind == reflect.Struct {
|
if kind == reflect.Struct {
|
||||||
suffix = "."
|
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 is anonymous add the child fields as well
|
||||||
if field.Anonymous {
|
if field.Anonymous {
|
||||||
suggestions = append(suggestions, getStructFields(f.Field(j), prefix)...)
|
suggestions = append(suggestions, getStructFields(f.Field(j), prefix)...)
|
||||||
|
} else if strings.HasPrefix(fname, prefix) {
|
||||||
|
// add field name with suffix
|
||||||
|
suggestions = append(suggestions, fname+suffix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,12 +79,12 @@ func TestAutocompleteFormat(t *testing.T) {
|
||||||
{
|
{
|
||||||
"fist level struct field name",
|
"fist level struct field name",
|
||||||
"{{.",
|
"{{.",
|
||||||
[]string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Car2.", "{{.Anonymous.", "{{.Hello}}"},
|
[]string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Car2.", "{{.Hello}}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fist level struct field name",
|
"fist level struct field name",
|
||||||
"{{ .",
|
"{{ .",
|
||||||
[]string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Car2.", "{{ .Anonymous.", "{{ .Hello}}"},
|
[]string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Car2.", "{{ .Hello}}"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fist level struct field name",
|
"fist level struct field name",
|
||||||
|
|
Loading…
Reference in New Issue