diff options
| author | Alex Flint <[email protected]> | 2021-09-18 08:55:40 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2021-09-18 08:55:40 -0700 |
| commit | f2f876420ce7c64673cdf97ed8071db8ef46e5f2 (patch) | |
| tree | 8441653724d058566ba492200900a5c6cca84d17 /parse.go | |
| parent | 7cc8da61cf3da353167fcc83ad4e751f3c82ec97 (diff) | |
| parent | 66cb696e79be30bc979cb003ef8bdecc78266ced (diff) | |
Merge remote-tracking branch 'origin/master' into usage-for-subcommands
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{ |
