summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorAlexey Trofimov <[email protected]>2023-01-18 11:50:50 +0300
committerAlexey Trofimov <[email protected]>2023-01-18 11:50:50 +0300
commitcef66fd2f6e0e061ade3778d3d3868032e4f0a32 (patch)
tree17ecbe31d927fd13e6454487ad62388abb2d4281 /parse.go
parent727f8533acca70ca429dce4bfea729a6af75c3f7 (diff)
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..3efe858 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
+
+ // IgnoreDefault 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 {