mirror of
https://github.com/containers/podman.git
synced 2025-06-28 06:18:57 +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
|
// loop over all field names
|
||||||
for j := 0; j < f.NumField(); j++ {
|
for j := 0; j < f.NumField(); j++ {
|
||||||
field := f.Type().Field(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
|
fname := field.Name
|
||||||
suffix := "}}"
|
suffix := "}}"
|
||||||
kind := field.Type.Kind()
|
kind := field.Type.Kind()
|
||||||
|
@ -31,6 +31,12 @@ func (c *Car) Color() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is for reflect testing required.
|
||||||
|
// nolint:unused
|
||||||
|
func (c Car) internal() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func TestAutocompleteFormat(t *testing.T) {
|
func TestAutocompleteFormat(t *testing.T) {
|
||||||
testStruct := struct {
|
testStruct := struct {
|
||||||
Name string
|
Name string
|
||||||
@ -38,6 +44,7 @@ func TestAutocompleteFormat(t *testing.T) {
|
|||||||
Car *Car
|
Car *Car
|
||||||
Car2 *Car
|
Car2 *Car
|
||||||
*Anonymous
|
*Anonymous
|
||||||
|
private int
|
||||||
}{}
|
}{}
|
||||||
|
|
||||||
testStruct.Car = &Car{}
|
testStruct.Car = &Car{}
|
||||||
|
Reference in New Issue
Block a user