summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2022-05-16 14:30:45 +0200
committerPaul Holzinger <pholzing@redhat.com>2022-05-18 18:24:41 +0200
commiteeeb88a667141380b843d92eb4478553b2256f17 (patch)
tree38adb720cfd41853da6f694288c4daa02882b0ab
parent7093885df73989acd2aa2dd936695d0b30a3dcf8 (diff)
downloadpodman-eeeb88a667141380b843d92eb4478553b2256f17.tar.gz
podman-eeeb88a667141380b843d92eb4478553b2256f17.tar.bz2
podman-eeeb88a667141380b843d92eb4478553b2256f17.zip
shell completion --format: only show exported fields
go templates only support exported fields, so the completion logic must filter the private fields out. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
-rw-r--r--cmd/podman/common/completion.go5
-rw-r--r--cmd/podman/common/completion_test.go7
2 files changed, 12 insertions, 0 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index e07e28dab..0db9f7351 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -1054,6 +1054,11 @@ func getStructFields(f reflect.Value, prefix string) []string {
// loop over all field names
for j := 0; j < f.NumField(); j++ {
field := f.Type().Field(j)
+ // check if struct field is not exported, templates only use exported fields
+ // PkgPath is always empty for exported fields
+ if field.PkgPath != "" {
+ continue
+ }
fname := field.Name
suffix := "}}"
kind := field.Type.Kind()
diff --git a/cmd/podman/common/completion_test.go b/cmd/podman/common/completion_test.go
index 13f45a662..c9e189961 100644
--- a/cmd/podman/common/completion_test.go
+++ b/cmd/podman/common/completion_test.go
@@ -31,6 +31,12 @@ func (c *Car) Color() string {
return ""
}
+// This is for reflect testing required.
+// nolint:unused
+func (c Car) internal() int {
+ return 0
+}
+
func TestAutocompleteFormat(t *testing.T) {
testStruct := struct {
Name string
@@ -38,6 +44,7 @@ func TestAutocompleteFormat(t *testing.T) {
Car *Car
Car2 *Car
*Anonymous
+ private int
}{}
testStruct.Car = &Car{}