-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
error when arg has same name as option #346
Comments
Upon further inspection, this seems to be an error in the logic in parseArgs(). It strips the first argument off the list of arguments if it has a listener. This I believe is in the case of actions. Unfortunately, the listeners for both actions and options share the same space, and can end up having the same name, as in my case above. I'm not sure, at this moment anyway, what the least invasive way to fix this would be. I'm investigating, but would love to hear if there's a simple way to avoid this. |
Issue #346, fix collisions when option and first arg have same name
Revert "Issue #346, fix collisions when option and first arg have same n...
Can we re-open this as it was reverted because it introduced a bug? |
…ting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 0.19.1 would instead translate to 0.19.1. This logic can subsequently be removed once this issue is resolved.
…ting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing \`yarn version\` would instead translate to \`yarn --version\`. This logic can subsequently be removed once this issue is resolved.
…ting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
…ting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
… (#2510) * Fix `yarn version` which yields same output as `yarn --version` (#2491) There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name `version` was shared. In other words, executing the command `yarn version` would yield the same output as `yarn --version`. This relates to PR #2268. * Shift first arg that shares name with an option to circumvent conflicting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
… (#2510) * Fix `yarn version` which yields same output as `yarn --version` (#2491) There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name `version` was shared. In other words, executing the command `yarn version` would yield the same output as `yarn --version`. This relates to PR #2268. * Shift first arg that shares name with an option to circumvent conflicting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
… (#2510) * Fix `yarn version` which yields same output as `yarn --version` (#2491) There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name `version` was shared. In other words, executing the command `yarn version` would yield the same output as `yarn --version`. This relates to PR #2268. * Shift first arg that shares name with an option to circumvent conflicting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
…pkg#2491) (yarnpkg#2510) * Fix `yarn version` which yields same output as `yarn --version` (yarnpkg#2491) There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name `version` was shared. In other words, executing the command `yarn version` would yield the same output as `yarn --version`. This relates to PR yarnpkg#2268. * Shift first arg that shares name with an option to circumvent conflicting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
This has not had much recent activity, but is a bug and has been reported again. Keeping this one open and closing the others. |
Reading through the closed duplicate bugs, I saw links from tslint and yargs noticing this issue. |
This issue was fixed by #494. Thank you for your contributions. |
…1) (#2510) * Fix `yarn version` which yields same output as `yarn --version` (#2491) There was a conflict when commander attempts to parse the incoming args between the command executed and the options since the name `version` was shared. In other words, executing the command `yarn version` would yield the same output as `yarn --version`. This relates to PR #2268. * Shift first arg that shares name with an option to circumvent conflicting name bug Relating to tj/commander.js#346, when an arg shares the same name as an option, it wrongly ignores the arg command and executes the option instead. Therefore, executing 'yarn version' would instead translate to 'yarn --version'. This logic can subsequently be removed once this issue is resolved.
It appears that when you give commander an arg that has the same name as an option, it wrongly sees that arg as an option. This only seems to occur when the arg name that matches an option name is the first arg. Take the following test case:
Now here are some outputs from it, notice that only when the first arg matches the option name does the error in the opts field occur:
The error cases, if not apparent, are when the opts equal
opts: {"registry":[]}
. Because this occurs only with the first argument, I wonder if this has to do somehow with an error in subcommand processing, even though I specified no commands. Just for a bit more detail, this is the full output of theprogram
object in the last error case:The text was updated successfully, but these errors were encountered: