Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(setArg): options using camel-case and dot-notation populated twice #268

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion index.js
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
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