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
Dash inside option name with parser option strip-dashed yields undefined value #2311
Comments
@koraa thank you for the bug report. I went ahead and transferred this over to Although, the fact that |
I just noticed a similar (probably the same) bug: I have options that are paths (e.g. .parserConfiguration({
'strip-aliased': true,
'strip-dashed': true
}) and configured the path options with |
Thanks for the report. I recently looked into some related issues in yargs@17.x and opened a PR to (hopefully) fix the interaction of coerce and non-default configuration settings. I am confident enough that this will fix the issues, I'll move this issue back to yargs! |
Clever having the reproduction on the command-line. The behaviour has changed in current yargs version, but still broken as coerce is not run:
Running against #2308 code:
|
This is a bug report; minimal example of the bug:
$ node -e "console.log(require('yargs').parserConfiguration({ 'strip-dashed': true}).option('foo-bar', { coerce: (v) => v }).parse(['executable', '--foo-bar', 'hello']))"
outputs:
This is incorrect. The value of 'fooBar' should be 'hello', not undefined and the 'foo-bar' property should be entirely removed.
This bug does not appear with options not containing a dash:
node -e "console.log(require('yargs').parserConfiguration({ 'strip-dashed': true}).option('foobar', { coerce: (v) => v }).parse(['executable', '--foobar', 'hello']))"
yields the following correct output:
Workaround No 1
Setting 'strip-dashed' to false yields correct behaviour:
node -e "console.log(require('yargs').parserConfiguration({ 'strip-dashed': false }).option('foo-bar', { coerce: (v) => v }).parse(['executable', '--foo-bar', 'hello']))"
resulting js:
Woraround No 2
Using an alias also yields less wrong behavior (still no stripping).
node -e "console.log(require('yargs').parserConfiguration({ 'strip-dashed': true}).option('foobar', { alias: ['foo-bar'], coerce: (v) => v }).parse(['executable', '--foo-bar', 'hello']))"
Output:
The text was updated successfully, but these errors were encountered: