Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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