Skip to content

Commit 60f2db5

Browse files
authored
fix: unknown-options-as-args now respects short-option-groups (#510)
1 parent 214983c commit 60f2db5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/yargs-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ export class YargsParser {
975975
// ignore negative numbers
976976
if (arg.match(negative)) { return false }
977977
// if this is a short option group and all of them are configured, it isn't unknown
978-
if (hasAllShortFlags(arg)) { return false }
978+
if (configuration['short-option-groups'] && hasAllShortFlags(arg)) { return false }
979979
// e.g. '--count=2'
980980
const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/
981981
// e.g. '-a' or '--arg'

test/yargs-parser.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3249,7 +3249,7 @@ describe('yargs-parser', function () {
32493249
v: true
32503250
})
32513251
})
3252-
// Fixes: https://github.com/yargs/yargs-parser/issues/501
3252+
// Fixes: https://github.com/yargs/yargs-parser/issues/501
32533253
it('should allow an unknown arg that resembles a known arg and contains hyphens to be used as the value of another flag in short form', function () {
32543254
{
32553255
const argv = parser('--known-arg /1/ -k --known-arg-unknown', {
@@ -3346,6 +3346,18 @@ describe('yargs-parser', function () {
33463346
})
33473347
}
33483348
})
3349+
it('should not parse known short option groups when short-option-groups:false', function () {
3350+
const argv = parser('-known', {
3351+
boolean: ['k', 'n', 'o', 'w', 'n'],
3352+
configuration: {
3353+
'unknown-options-as-args': true,
3354+
'short-option-groups': false
3355+
}
3356+
})
3357+
argv.should.deep.equal({
3358+
_: ['-known']
3359+
})
3360+
})
33493361
it('should parse negative numbers', function () {
33503362
const argv = parser('-k -33', {
33513363
boolean: ['k'],

0 commit comments

Comments
 (0)