Skip to content

Commit

Permalink
fix: nargs was consuming too many arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin committed Jan 20, 2018
1 parent 9734d9c commit 4fef206
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down
10 changes: 10 additions & 0 deletions test/yargs-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 4fef206

Please sign in to comment.