diff --git a/lib/yargs-parser.ts b/lib/yargs-parser.ts index bef72050..48a2d0f2 100644 --- a/lib/yargs-parser.ts +++ b/lib/yargs-parser.ts @@ -975,7 +975,7 @@ export class YargsParser { // ignore negative numbers if (arg.match(negative)) { return false } // if this is a short option group and all of them are configured, it isn't unknown - if (hasAllShortFlags(arg)) { return false } + if (configuration['short-option-groups'] && hasAllShortFlags(arg)) { return false } // e.g. '--count=2' const flagWithEquals = /^-+([^=]+?)=[\s\S]*$/ // e.g. '-a' or '--arg' diff --git a/test/yargs-parser.mjs b/test/yargs-parser.mjs index 30c0dd07..4c692375 100644 --- a/test/yargs-parser.mjs +++ b/test/yargs-parser.mjs @@ -3249,7 +3249,7 @@ describe('yargs-parser', function () { v: true }) }) - // Fixes: https://github.com/yargs/yargs-parser/issues/501 + // Fixes: https://github.com/yargs/yargs-parser/issues/501 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 () { { const argv = parser('--known-arg /1/ -k --known-arg-unknown', { @@ -3346,6 +3346,18 @@ describe('yargs-parser', function () { }) } }) + it('should not parse known short option groups when short-option-groups:false', function () { + const argv = parser('-known', { + boolean: ['k', 'n', 'o', 'w', 'n'], + configuration: { + 'unknown-options-as-args': true, + 'short-option-groups': false + } + }) + argv.should.deep.equal({ + _: ['-known'] + }) + }) it('should parse negative numbers', function () { const argv = parser('-k -33', { boolean: ['k'],