Skip to content

Commit

Permalink
fix(unknown-options-as-args): '--' is not an unknown option (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur authored and bcoe committed Oct 15, 2019
1 parent afcaecb commit 3fee2d8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion index.js
Expand Up @@ -143,7 +143,8 @@ function parse (args, opts) {
var next
var value

if (isUnknownOptionAsArg(arg)) {
// any unknown option (except for end-of-options, "--")
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
argv._.push(arg)
// -- separated by =
} else if (arg.match(/^--.+=/) || (
Expand Down
30 changes: 30 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -2894,6 +2894,36 @@ describe('yargs-parser', function () {
k: true
})
})

it('should not identify "--" as an unknown option', function () {
const argv = parser('-a -k one -1 -- -b -k two -2', {
boolean: ['k'],
configuration: {
'unknown-options-as-args': true
}
})
argv.should.deep.equal({
_: ['-a', 'one', -1, '-b', '-k', 'two', '-2'],
k: true
})
})

it('should not identify "--" as an unknown option when "populate--" is true', function () {
const argv = parser('-a -k one -1 -- -b -k two -2', {
boolean: ['k'],
configuration: {
'populate--': true,
'unknown-options-as-args': true
}
})
argv.should.deep.equal({
// populate argv._ with everything before the --
_: ['-a', 'one', -1],
// and argv['--'] with everything after the --
'--': ['-b', '-k', 'two', '-2'],
k: true
})
})
})
})

Expand Down

0 comments on commit 3fee2d8

Please sign in to comment.