Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 13 additions & 1 deletion test/yargs-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down Expand Up @@ -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'],
Expand Down