diff --git a/index.js b/index.js index 20d472d1..65b418e8 100644 --- a/index.js +++ b/index.js @@ -667,6 +667,14 @@ function parse (args, opts) { var isValueArray = Array.isArray(value) var duplicate = configuration['duplicate-arguments-array'] + // nargs has higher priority than duplicate + if (!duplicate && checkAllAliases(key, flags.nargs)) { + duplicate = true + if ((typeof o[key] === 'string' && flags.nargs[key] === 1) || (Array.isArray(o[key]) && o[key].length === flags.nargs[key])) { + o[key] = undefined + } + } + if (value === increment) { o[key] = increment(o[key]) } else if (Array.isArray(o[key])) { diff --git a/test/yargs-parser.js b/test/yargs-parser.js index ee76e417..9e313479 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -2189,6 +2189,16 @@ describe('yargs-parser', function () { parsed['x'].should.equal('b') }) + it('does not interfere with nargs', function () { + var parsed = parser('-x a b c -x o p q', { + narg: { x: 3 }, + configuration: { + 'duplicate-arguments-array': false + } + }) + + parsed['x'].should.deep.equal(['o', 'p', 'q']) + }) }) describe('flatten duplicate arrays', function () { @@ -2232,7 +2242,6 @@ describe('yargs-parser', function () { parsed['x'].should.deep.equal(['a', 'b']) }) - it('flattens duplicate array type, when argument uses dot notation', function () { var parsed = parser('-x.foo a -x.foo b', { array: ['x.foo'],