summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--parse.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/parse.go b/parse.go
index cb8be6d..63059fc 100644
--- a/parse.go
+++ b/parse.go
@@ -283,6 +283,7 @@ func cmdFromStruct(name string, dest path, t reflect.Type) (*command, error) {
cmdname = strings.ToLower(field.Name)
}
+ // parse the subcommand recursively
subcmd, err := cmdFromStruct(cmdname, subdest, field.Type)
if err != nil {
errs = append(errs, err.Error())
@@ -445,6 +446,10 @@ func (p *Parser) process(args []string) error {
return fmt.Errorf("invalid subcommand: %s", arg)
}
+ // instantiate the field to point to a new struct
+ v := p.writable(subcmd.dest)
+ v.Set(reflect.New(v.Type().Elem())) // we already checked that all subcommands are struct pointers
+
// add the new options to the set of allowed options
specs = append(specs, subcmd.specs...)