citty icon indicating copy to clipboard operation
citty copied to clipboard

main command's positional arg's value is the same as a subCommand name

Open zuixinwang opened this issue 2 years ago • 3 comments

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

zuixinwang avatar Jun 16 '23 01:06 zuixinwang

Maybe it should not have positional args if subCommands exist Should it have a validation?

zuixinwang avatar Jul 06 '23 02:07 zuixinwang

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.

nozomuikuta avatar Jul 06 '23 06:07 nozomuikuta

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.

pi0 avatar Sep 09 '23 12:09 pi0