Yargs version used: 18.0.0
How to reproduce
const parser = require('yargs-parser')
parser("-x 3 -x 1")
returns
i.e., it wrongfully calculated 3 + 1 = 4.
Expected would be
The option "duplicate-arguments-array": false still results in 4.
If the order is changed, i.e.,
const parser = require('yargs-parser')
parser("-x 1 -x 3")
then the result is correct.
Bug Cause
The increment happens in yargs-parser.ts -> setKey at this code line:
if (value === increment()) {
o[key] = increment(o[key])
}
increment() === 1, i.e., it increments o[key] each time we have any argument which equals to 1.
The increment function has a comment on top stating that it "should only be called when a count is given as an arg". Obviously, we have a number and not a count here.
Workaround
A workaround in yargs/yargs consists in setting type="string".
Yargs version used:
18.0.0How to reproduce
returns
i.e., it wrongfully calculated
3 + 1 = 4.Expected would be
The option
"duplicate-arguments-array": falsestill results in4.If the order is changed, i.e.,
then the result is correct.
Bug Cause
The increment happens in
yargs-parser.ts->setKeyat this code line:increment() === 1, i.e., it incrementso[key]each time we have any argument which equals to1.The increment function has a comment on top stating that it "should only be called when a count is given as an arg". Obviously, we have a number and not a count here.
Workaround
A workaround in
yargs/yargsconsists in settingtype="string".