diff options
| author | Alex Flint <[email protected]> | 2019-04-30 13:40:45 -0700 |
|---|---|---|
| committer | Alex Flint <[email protected]> | 2019-04-30 13:40:45 -0700 |
| commit | a78c6ded26bda9fdce7f4f3bef07ae2e9acad1cf (patch) | |
| tree | 8c19cd5bc9e927a7bf7e5ea5120eef681fad9904 /parse.go | |
| parent | af12b7cfc22b056f6232bb25f5f4b7d35ca37e7e (diff) | |
set subcommand structs to be struct pointers
Diffstat (limited to 'parse.go')
| -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...) |
