-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
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:
{
_: [ 'executable' ],
fooBar: undefined,
'$0': '',
'foo-bar': undefined
}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:
{ _: [ 'executable' ], foobar: 'hello', '$0': '' }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:
{ _: [ 'executable' ], 'foo-bar': 'hello', fooBar: 'hello', '$0': '' }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:
{
_: [ 'executable' ],
foobar: 'hello',
fooBar: 'hello',
'$0': '',
'foo-bar': 'hello'
}Reactions are currently unavailable