summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlex Flint <[email protected]>2023-01-27 08:35:12 -0800
committerGitHub <[email protected]>2023-01-27 08:35:12 -0800
commitc0a8e20a0ac9e8a9dbb0e078b0befd8e28302e8b (patch)
treea10ecad9ff0307d323947b3cbef8d886f4b63101 /parse.go
parent727f8533acca70ca429dce4bfea729a6af75c3f7 (diff)
parent5036dce2d6a64b2dd1b6e270947bde1e8110708c (diff)
Merge pull request #205 from dmzkrsk/strict-subgroup-parsing
add strict subcommand parsing
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/parse.go b/parse.go
index 6ac5e99..b935fad 100644
--- a/parse.go
+++ b/parse.go
@@ -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 {