Skip to content

Commit

Permalink
fix(setArg): options using camel-case and dot-notation populated twice (
Browse files Browse the repository at this point in the history
  • Loading branch information
mleguen authored Apr 16, 2020
1 parent 78014fc commit f7e15b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,11 @@ function parse (args, opts) {
a.shift() // nuke the old key.
x = x.concat(a)

setKey(argv, x, value)
// populate alias only if is not already an alias of the full key
// (already populated above)
if (!(flags.aliases[key] || []).includes(x.join('.'))) {
setKey(argv, x, value)
}
})
}

Expand Down
14 changes: 14 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,20 @@ describe('yargs-parser', function () {
})

argv.f.bar.should.eql(99)
argv.foo.bar.should.eql(99)
})

// see #267
it('should populate aliases when dot notation is used on camel-cased option', function () {
var argv = parser(['--foo-baz.bar', '99'], {
alias: {
'foo-baz': ['f']
}
})

argv.f.bar.should.eql(99)
argv['foo-baz'].bar.should.eql(99)
argv.fooBaz.bar.should.eql(99)
})

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

0 comments on commit f7e15b9

Please sign in to comment.