diff --git a/index.js b/index.js index 5c5638bd..6405e571 100644 --- a/index.js +++ b/index.js @@ -315,7 +315,7 @@ function parse (args, opts) { if (available < toEat) error = Error(__('Not enough arguments following: %s', key)) - for (ii = i + 1; ii < (available + i + 1); ii++) { + for (ii = i + 1; ii < (Math.min(available, toEat) + i + 1); ii++) { setArg(key, args[ii]) } diff --git a/test/yargs-parser.js b/test/yargs-parser.js index 6e1ae0cf..c1e3ff1e 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -1653,6 +1653,16 @@ describe('yargs-parser', function () { result.error.message.should.equal('Not enough arguments following: foo') }) + + it('should not consume more than configured nargs', function () { + var result = parser(['--foo', 'a', 'b'], { + narg: { + foo: 1 + } + }) + + result.foo.should.eql('a') + }) }) describe('env vars', function () {