summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2021-09-18 08:55:40 -0700
committerAlex Flint <[email protected]>2021-09-18 08:55:40 -0700
commitf2f876420ce7c64673cdf97ed8071db8ef46e5f2 (patch)
tree8441653724d058566ba492200900a5c6cca84d17 /parse.go
parent7cc8da61cf3da353167fcc83ad4e751f3c82ec97 (diff)
parent66cb696e79be30bc979cb003ef8bdecc78266ced (diff)
Merge remote-tracking branch 'origin/master' into usage-for-subcommands
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/parse.go b/parse.go
index 40adbe1..1ebb2a4 100644
--- a/parse.go
+++ b/parse.go
@@ -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{