diff options
| author | Alex Flint <[email protected]> | 2023-01-27 08:35:12 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-01-27 08:35:12 -0800 |
| commit | c0a8e20a0ac9e8a9dbb0e078b0befd8e28302e8b (patch) | |
| tree | a10ecad9ff0307d323947b3cbef8d886f4b63101 /parse.go | |
| parent | 727f8533acca70ca429dce4bfea729a6af75c3f7 (diff) | |
| parent | 5036dce2d6a64b2dd1b6e270947bde1e8110708c (diff) | |
Merge pull request #205 from dmzkrsk/strict-subgroup-parsing
add strict subcommand parsing
Diffstat (limited to 'parse.go')
| -rw-r--r-- | parse.go | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -115,6 +115,10 @@ type Config struct { // IgnoreDefault instructs the library not to reset the variables to the // default values, including pointers to sub commands IgnoreDefault bool + + // StrictSubcommands intructs the library not to allow global commands after + // subcommand + StrictSubcommands bool } // Parser represents a set of command line options with destination values @@ -588,7 +592,12 @@ func (p *Parser) process(args []string) error { } // add the new options to the set of allowed options - specs = append(specs, subcmd.specs...) + if p.config.StrictSubcommands { + specs = make([]*spec, len(subcmd.specs)) + copy(specs, subcmd.specs) + } else { + specs = append(specs, subcmd.specs...) + } // capture environment vars for these new options if !p.config.IgnoreEnv { |
