Skip to content

Commit

Permalink
fix(dot-notation) fix issue with disabled dot-notation when aliases a…
Browse files Browse the repository at this point in the history
…re in use
  • Loading branch information
elas7 authored and bcoe committed Apr 9, 2016
1 parent a867165 commit 90b871f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
21 changes: 10 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,28 +343,27 @@ function parse (args, opts) {
var splitKey = key.split('.')
setKey(argv, splitKey, value)

// alias references an inner-value within
// a dot-notation object. see #279.
if (~key.indexOf('.') && flags.aliases[key]) {
// handle populating aliases of the full key
if (flags.aliases[key]) {
flags.aliases[key].forEach(function (x) {
x = x.split('.')
setKey(argv, x, value)
})
}

;(flags.aliases[splitKey[0]] || []).forEach(function (x) {
x = x.split('.')
// handle populating aliases of the first element of the dot-notation key
if (splitKey.length > 1 && configuration['dot-notation']) {
;(flags.aliases[splitKey[0]] || []).forEach(function (x) {
x = x.split('.')

// handle populating dot notation for both
// the key and its aliases.
if (splitKey.length > 1) {
// expand alias with nested objects in key
var a = [].concat(splitKey)
a.shift() // nuke the old key.
x = x.concat(a)
}

setKey(argv, x, value)
})
setKey(argv, x, value)
})
}

// Set normalize getter and setter when key is in 'normalize' but isn't an array
if (checkAllAliases(key, flags.normalize) && !checkAllAliases(key, flags.arrays)) {
Expand Down
13 changes: 13 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,19 @@ describe('yargs-parser', function () {

expect(parsed['alias.bar']).to.equal('abc')
})

it('does not expand alias of first element of dot notation arguments', function () {
var parsed = parser(['--foo.bar', 'banana'], {
alias: {
'foo': ['f']
},
configuration: {
'dot-notation': false
}
})
expect(parsed['foo.bar']).to.equal('banana')
expect(parsed).not.to.include.keys('f.bar')
})
})

describe('parse numbers', function () {
Expand Down

0 comments on commit 90b871f

Please sign in to comment.