main command's positional arg's value is the same as a subCommand name
Environment
v16.14.2
Reproduction
https://stackblitz.com/edit/stackblitz-starters-qggkrd?file=index.js
Describe the bug
when the main command's first positional arg's value is the same as a subCommand name the subCommand runs and the main command runs with the positional arg's value
Additional context
No response
Logs
No response
Maybe it should not have positional args if subCommands exist Should it have a validation?
It is natural to prevent positional arg and sub command from having same name to avoid ambiguity in terms of parsing.
But, extremely it depends on tool design which should have precedence over the other. If accepting same name, IMHO, since main command has precedence over sub command, its argument(s) should also have it over sub command. 🤔
Or, another way of thinking is that commands as a whole have precedence over arguments.
@pi0
We need your thought as author, so that we can implement such validation.
- Prevent same name?
- Accept and give precedence to either?
- etc.
Hi. Thinking more, i think probably we should only run main run only when no subcommand is being matched. We have setup hook that always get called. It is a breaking change. Feedbacks welcome about this change.