Skip to content

Commit 48a99d9

Browse files
authored
Merge branch 'main' into fix-no-negated-with-unknown
2 parents f85e0c8 + 60f2db5 commit 48a99d9

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
@@ -3261,7 +3261,7 @@ describe('yargs-parser', function () {
32613261
v: true
32623262
})
32633263
})
3264-
// Fixes: https://github.com/yargs/yargs-parser/issues/501
3264+
// Fixes: https://github.com/yargs/yargs-parser/issues/501
32653265
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 () {
32663266
{
32673267
const argv = parser('--known-arg /1/ -k --known-arg-unknown', {
@@ -3358,6 +3358,18 @@ describe('yargs-parser', function () {
33583358
})
33593359
}
33603360
})
3361+
it('should not parse known short option groups when short-option-groups:false', function () {
3362+
const argv = parser('-known', {
3363+
boolean: ['k', 'n', 'o', 'w', 'n'],
3364+
configuration: {
3365+
'unknown-options-as-args': true,
3366+
'short-option-groups': false
3367+
}
3368+
})
3369+
argv.should.deep.equal({
3370+
_: ['-known']
3371+
})
3372+
})
33613373
it('should parse negative numbers', function () {
33623374
const argv = parser('-k -33', {
33633375
boolean: ['k'],

0 commit comments

Comments
 (0)