diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-04-28 14:49:03 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-04-28 15:11:21 +0200 |
commit | f93ba587c608e2678b176f1460b32e8a144edf1a (patch) | |
tree | b2c6b5ce5b7e571b33fb77146ef4bf1c0d7c9162 /cmd/podman/common/completion_test.go | |
parent | 2b8cafc0671fbbd155770f044b8216f050877192 (diff) | |
download | podman-f93ba587c608e2678b176f1460b32e8a144edf1a.tar.gz podman-f93ba587c608e2678b176f1460b32e8a144edf1a.tar.bz2 podman-f93ba587c608e2678b176f1460b32e8a144edf1a.zip |
shell completion --format: work with nil structs
AutocompleteFormat() takes the format struct as argument. Often the structs
are deeply nested and contain other structs. Up until now if there was a
pointer to a struct the logic was not able to get the field names from
that, simply because the pointer was nil. However it is possible to
create a new initialized type with reflect.New(). This allows us to
complete all struct fields/functions even when there nil pointers.
Therefore we can drop the extra initialization which was done by some
callers.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'cmd/podman/common/completion_test.go')
-rw-r--r-- | cmd/podman/common/completion_test.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cmd/podman/common/completion_test.go b/cmd/podman/common/completion_test.go index d28ac3928..bfff9a96e 100644 --- a/cmd/podman/common/completion_test.go +++ b/cmd/podman/common/completion_test.go @@ -34,10 +34,9 @@ func TestAutocompleteFormat(t *testing.T) { Name string Age int Car *Car + Car2 *Car *Anonymous - }{ - Anonymous: &Anonymous{}, - } + }{} testStruct.Car = &Car{} testStruct.Car.Extras = map[string]string{"test": "1"} @@ -80,12 +79,12 @@ func TestAutocompleteFormat(t *testing.T) { { "fist level struct field name", "{{.", - []string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Anonymous.", "{{.Hello}}"}, + []string{"{{.Name}}", "{{.Age}}", "{{.Car.", "{{.Car2.", "{{.Anonymous.", "{{.Hello}}"}, }, { "fist level struct field name", "{{ .", - []string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Anonymous.", "{{ .Hello}}"}, + []string{"{{ .Name}}", "{{ .Age}}", "{{ .Car.", "{{ .Car2.", "{{ .Anonymous.", "{{ .Hello}}"}, }, { "fist level struct field name", @@ -103,6 +102,11 @@ func TestAutocompleteFormat(t *testing.T) { []string{"{{ .Car.Brand}}"}, }, { + "second level nil struct field name", + "{{ .Car2.", + []string{"{{ .Car2.Brand}}", "{{ .Car2.Stats.", "{{ .Car2.Extras}}", "{{ .Car2.Color}}", "{{ .Car2.Type}}"}, + }, + { "three level struct field name", "{{ .Car.Stats.", []string{"{{ .Car.Stats.HP}}", "{{ .Car.Stats.Displacement}}"}, |