Skip to content
Open
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
5 changes: 4 additions & 1 deletion lib/yargs-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,10 @@ export class YargsParser {
// e.g. '-a' or '--arg'
const normalFlag = /^-+([^=]+?)$/
// check the different types of flag styles, including negatedBoolean, a pattern defined near the start of the parse method
return !hasFlagsMatching(arg, flagWithEquals, negatedBoolean, normalFlag)
const patterns = [flagWithEquals, normalFlag];
if (configuration['boolean-negation'])
patterns.push(negatedBoolean);
return !hasFlagsMatching(arg, ...patterns)
}

// make a best effort to pick a default value
Expand Down
12 changes: 12 additions & 0 deletions test/yargs-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3071,6 +3071,18 @@ describe('yargs-parser', function () {
knownArg: false
})
})
it('should ignore negated known options when boolean-negation:false', function () {
const argv = parser('--no-known-arg --no-unknown-arg', {
boolean: ['known-arg'],
configuration: {
'unknown-options-as-args': true,
'boolean-negation': false
}
})
argv.should.deep.equal({
_: ['--no-known-arg', '--no-unknown-arg']
})
})
it('should ignore unknown options in long format separated by space', function () {
const argv = parser('--known-arg a --unknown-arg b', {
string: ['known-arg'],
Expand Down