diff options
| -rw-r--r-- | parse.go | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -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...) |
