Skip to content

Commit 4fef206

Browse files
author
Benjamin
committed
fix: nargs was consuming too many arguments
1 parent 9734d9c commit 4fef206

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function parse (args, opts) {
315315

316316
if (available < toEat) error = Error(__('Not enough arguments following: %s', key))
317317

318-
for (ii = i + 1; ii < (available + i + 1); ii++) {
318+
for (ii = i + 1; ii < (Math.min(available, toEat) + i + 1); ii++) {
319319
setArg(key, args[ii])
320320
}
321321

test/yargs-parser.js

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

16541654
result.error.message.should.equal('Not enough arguments following: foo')
16551655
})
1656+
1657+
it('should not consume more than configured nargs', function () {
1658+
var result = parser(['--foo', 'a', 'b'], {
1659+
narg: {
1660+
foo: 1
1661+
}
1662+
})
1663+
1664+
result.foo.should.eql('a')
1665+
})
16561666
})
16571667

16581668
describe('env vars', function () {

0 commit comments

Comments
 (0)