diff --git a/index.js b/index.js index a3849bce..5fdb78e5 100644 --- a/index.js +++ b/index.js @@ -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 { diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 29104246..24a8f121 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -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'],