diff --git a/index.js b/index.js index a3849bce..4e6c47f8 100644 --- a/index.js +++ b/index.js @@ -166,12 +166,12 @@ function parse (args, opts) { )) { key = arg.match(/^--?(.+)/)[1] - // nargs format = '--foo a b c' - if (checkAllAliases(key, flags.nargs)) { - i = eatNargs(i, key, args) // array format = '--foo a b c' - } else if (checkAllAliases(key, flags.arrays) && args.length > i + 1) { + if (checkAllAliases(key, flags.arrays) && args.length > i + 1) { i = eatArray(i, key, args) + // nargs format = '--foo a b c' + } else if (checkAllAliases(key, flags.nargs)) { + i = eatNargs(i, key, args) } else { next = args[i + 1] diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 29104246..a1b3089f 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -1664,6 +1664,17 @@ describe('yargs-parser', function () { result.foo.should.eql('a') }) + + it('should be ignored if input is an array', function () { + var result = parser(['--foo', 'a', 'b'], { + array: 'foo', + narg: { + foo: 1 + } + }) + + result.foo.should.eql(['a', 'b']) + }) }) describe('env vars', function () {