Skip to content

Commit d0e64e5

Browse files
committed
fix: unknown-options-as-args now respects short-option-groups
1 parent 214983c commit d0e64e5

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-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: 12 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', {
@@ -3345,6 +3345,17 @@ describe('yargs-parser', function () {
33453345
k: ['--k-unknown', '--k-not-known']
33463346
})
33473347
}
3348+
it('should not parse known short option groups when short-option-groups:false', function () {
3349+
const argv = parser('-known', {
3350+
boolean: ['k', 'n', 'o', 'w', 'n'],
3351+
configuration: {
3352+
'unknown-options-as-args': true,
3353+
'short-option-groups': false
3354+
}
3355+
})
3356+
argv.should.deep.equal({
3357+
_: ['-known']
3358+
})
33483359
})
33493360
it('should parse negative numbers', function () {
33503361
const argv = parser('-k -33', {

0 commit comments

Comments
 (0)