diff options
| author | Alex Flint <[email protected]> | 2021-05-24 21:50:33 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-05-24 21:50:33 -0700 |
| commit | eb0393e9bc0bbd8d3cc37a6ee98c1d538e4e5c91 (patch) | |
| tree | 560557982ca2baefcfb6157cb9feece14e6b8663 /parse.go | |
| parent | 679be43af38a865f8318ed9bc3fde7ae424a2dad (diff) | |
| parent | fa12c02e81bdff1e9c11ee8a70b938b8c02da6b6 (diff) | |
Merge pull request #158 from alexflint/unexported-embeddedv1.4.2
Recurse into unexported embedded structs
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -257,17 +257,24 @@ func cmdFromStruct(name string, dest path, t reflect.Type) (*command, error) { var errs []string walkFields(t, func(field reflect.StructField, t reflect.Type) bool { - // Check for the ignore switch in the tag + // check for the ignore switch in the tag tag := field.Tag.Get("arg") - if tag == "-" || !isExported(field.Name) { + if tag == "-" { return false } - // If this is an embedded struct then recurse into its fields + // if this is an embedded struct then recurse into its fields, even if + // it is unexported, because exported fields on unexported embedded + // structs are still writable if field.Anonymous && field.Type.Kind() == reflect.Struct { return true } + // ignore any other unexported field + if !isExported(field.Name) { + return false + } + // duplicate the entire path to avoid slice overwrites subdest := dest.Child(field) spec := spec{ |
