Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unknown-options-as-args): '--' is not an unknown option #207

Merged
merged 1 commit into from
Oct 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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