Skip to content

Commit f7e15b9

Browse files
authored
fix(setArg): options using camel-case and dot-notation populated twice (#268)
1 parent 78014fc commit f7e15b9

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,11 @@ function parse (args, opts) {
480480
a.shift() // nuke the old key.
481481
x = x.concat(a)
482482

483-
setKey(argv, x, value)
483+
// populate alias only if is not already an alias of the full key
484+
// (already populated above)
485+
if (!(flags.aliases[key] || []).includes(x.join('.'))) {
486+
setKey(argv, x, value)
487+
}
484488
})
485489
}
486490

test/yargs-parser.js

+14
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,20 @@ describe('yargs-parser', function () {
959959
})
960960

961961
argv.f.bar.should.eql(99)
962+
argv.foo.bar.should.eql(99)
963+
})
964+
965+
// see #267
966+
it('should populate aliases when dot notation is used on camel-cased option', function () {
967+
var argv = parser(['--foo-baz.bar', '99'], {
968+
alias: {
969+
'foo-baz': ['f']
970+
}
971+
})
972+
973+
argv.f.bar.should.eql(99)
974+
argv['foo-baz'].bar.should.eql(99)
975+
argv.fooBaz.bar.should.eql(99)
962976
})
963977

964978
it('should populate aliases when nested dot notation is used', function () {

0 commit comments

Comments
 (0)