Skip to content

Commit 2bc395f

Browse files
laggingreflexbcoe
authored andcommitted
fix: flatten-duplicate-arrays:false for more than 2 arrays (#128)
1 parent 82f4ea5 commit 2bc395f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ function parse (args, opts) {
639639
o[key] = increment(o[key])
640640
} else if (Array.isArray(o[key])) {
641641
if (duplicate && isTypeArray && isValueArray) {
642-
o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : [o[key]].concat([value])
642+
o[key] = configuration['flatten-duplicate-arrays'] ? o[key].concat(value) : (Array.isArray(o[key][0]) ? o[key] : [o[key]]).concat([value])
643643
} else if (!duplicate && Boolean(isTypeArray) === Boolean(isValueArray)) {
644644
o[key] = value
645645
} else {

test/yargs-parser.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,16 @@ describe('yargs-parser', function () {
20882088

20892089
parsed['x'].should.deep.equal([['a', 'b'], ['c', 'd']])
20902090
})
2091+
it('nests duplicate array types of more than 2', function () {
2092+
var parsed = parser('-x a b -x c d -x e f -x g h', {
2093+
array: ['x'],
2094+
configuration: {
2095+
'flatten-duplicate-arrays': false
2096+
}
2097+
})
2098+
2099+
parsed['x'].should.deep.equal([['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h']])
2100+
})
20912101
it('doesn\'t nests single arrays', function () {
20922102
var parsed = parser('-x a b', {
20932103
array: ['x'],

0 commit comments

Comments
 (0)