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