Prevent specifying global args multiple times #3938
Labels
A-parsing
Area: Parser's logic and needs it changed somehow.
C-enhancement
Category: Raise on the bar on expectations
M-breaking-change
Meta: Implementing or merging this will introduce a breaking change.
S-waiting-on-design
Status: Waiting on user-facing design to be resolved before implementing
Please complete the following tasks
Clap Version
3.2.8
Describe your use case
When making an argument global with
Arg::global(true)
, it will be available to both the parent and child subcommand. To me this implies that this option is a single flag that can be modified from anywhere.However when specifying the global twice (e.g.
cmd --global x subcmd --global y
), the parent's assignment of the variable will be discarded in favor of the subcommand's. While this definitely is a possible way to handle this edgecase, I think this command invocation indicates that the user is doing something wrong and it would be better if clap could tell the user that what he's doing doesn't make any sense.In my specific scenario, I have a command which defaults to one of it subcommands, so
cmd --flag x
is the same ascmd list --flag x
, while there's also other subcommands likecmd foo --flag x
. One flag is shared between all subcommands (which I've tried making global), while some others are only available tocmd
andcmd list
. This would solve the issue of having an option that can be specified twice for that one shared flag, but I'd still need another solution preventing people from using the othercmd list
-specific flags which can also be used with justcmd
when another subcommand likecmd foo
is used. So it's possible that this feature request is just a band-aid rather than solving the root issue.Describe the solution you'd like
Emit an error when specifying the same global argument multiple times.
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: