Skip to content

Commit e1951ea

Browse files
committed
fix: unknown-options-as-args now respects short-option-groups
1 parent 553c808 commit e1951ea

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,18 @@ describe('yargs-parser', function () {
32183218
v: true
32193219
})
32203220
})
3221+
it('should not parse known short option groups when short-option-groups:false', function () {
3222+
const argv = parser('-known', {
3223+
boolean: ['k', 'n', 'o', 'w', 'n'],
3224+
configuration: {
3225+
'unknown-options-as-args': true,
3226+
'short-option-groups': false
3227+
}
3228+
})
3229+
argv.should.deep.equal({
3230+
_: ['-known']
3231+
})
3232+
})
32213233
it('should parse negative numbers', function () {
32223234
const argv = parser('-k -33', {
32233235
boolean: ['k'],

0 commit comments

Comments
 (0)