Skip to content

Commit 3fee2d8

Browse files
evocateurbcoe
authored andcommitted
fix(unknown-options-as-args): '--' is not an unknown option (#207)
1 parent afcaecb commit 3fee2d8

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ function parse (args, opts) {
143143
var next
144144
var value
145145

146-
if (isUnknownOptionAsArg(arg)) {
146+
// any unknown option (except for end-of-options, "--")
147+
if (arg !== '--' && isUnknownOptionAsArg(arg)) {
147148
argv._.push(arg)
148149
// -- separated by =
149150
} else if (arg.match(/^--.+=/) || (

test/yargs-parser.js

+30
Original file line numberDiff line numberDiff line change
@@ -2894,6 +2894,36 @@ describe('yargs-parser', function () {
28942894
k: true
28952895
})
28962896
})
2897+
2898+
it('should not identify "--" as an unknown option', function () {
2899+
const argv = parser('-a -k one -1 -- -b -k two -2', {
2900+
boolean: ['k'],
2901+
configuration: {
2902+
'unknown-options-as-args': true
2903+
}
2904+
})
2905+
argv.should.deep.equal({
2906+
_: ['-a', 'one', -1, '-b', '-k', 'two', '-2'],
2907+
k: true
2908+
})
2909+
})
2910+
2911+
it('should not identify "--" as an unknown option when "populate--" is true', function () {
2912+
const argv = parser('-a -k one -1 -- -b -k two -2', {
2913+
boolean: ['k'],
2914+
configuration: {
2915+
'populate--': true,
2916+
'unknown-options-as-args': true
2917+
}
2918+
})
2919+
argv.should.deep.equal({
2920+
// populate argv._ with everything before the --
2921+
_: ['-a', 'one', -1],
2922+
// and argv['--'] with everything after the --
2923+
'--': ['-b', '-k', 'two', '-2'],
2924+
k: true
2925+
})
2926+
})
28972927
})
28982928
})
28992929

0 commit comments

Comments
 (0)