Skip to content

Commit

Permalink
fix: flatten-duplicate-arrays:false for more than 2 arrays (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
laggingreflex authored and bcoe committed Oct 6, 2018
1 parent 82f4ea5 commit 2bc395f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ function parse (args, opts) {
o[key] = increment(o[key])
} else if (Array.isArray(o[key])) {
if (duplicate && isTypeArray && isValueArray) {
o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : [o[key]].concat([value])
o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value])
} else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
o[key] = value
} else {
Expand Down
10 changes: 10 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2088,6 +2088,16 @@ describe('yargs-parser', function () {

parsed['x'].should.deep.equal([['a', 'b'], ['c', 'd']])
})
it('nests duplicate array types of more than 2', function () {
var parsed = parser('-x a b -x c d -x e f -x g h', {
array: ['x'],
configuration: {
'flatten-duplicate-arrays': false
}
})

parsed['x'].should.deep.equal([['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']])
})
it('doesn\'t nests single arrays', function () {
var parsed = parser('-x a b', {
array: ['x'],
Expand Down

0 comments on commit 2bc395f

Please sign in to comment.