Skip to content

Commit

Permalink
fix: make requiresArg work in conjunction with arrays (yargs#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmx authored and bcoe committed Oct 6, 2018
1 parent 7df1bd4 commit 77ae1d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,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]

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

0 comments on commit 77ae1d4

Please sign in to comment.