Skip to content

fix: flags without an alias incorrectly reported as unknown in strict mode#30

Closed
xxiaoxiong wants to merge 1 commit into
lukeed:masterfrom
xxiaoxiong:fix/strict-unknown-flags
Closed

fix: flags without an alias incorrectly reported as unknown in strict mode#30
xxiaoxiong wants to merge 1 commit into
lukeed:masterfrom
xxiaoxiong:fix/strict-unknown-flags

Conversation

@xxiaoxiong

@xxiaoxiong xxiaoxiong commented May 30, 2026

Copy link
Copy Markdown

Summary

Fixes strict mode (unknown callback) incorrectly reporting flags that have no alias as "unknown" when they are listed in string or boolean options.

Changes

  • src/index.js: Extended keys array to include opts.boolean and opts.string entries alongside alias keys

Why

In strict mode, keys was built only from opts.alias entries. A flag like --bar listed in string: ['bar'] with no corresponding alias would be rejected as unknown, even though it's a valid recognized flag.

Repro:

mri(['--bar'], {
  string: ['foo', 'bar'],
  alias: { f: 'foo' },
  unknown(flag) { console.error('Unknown:', flag); process.exit(1); }
})
// Before: "Unknown: --bar"
// After: parses correctly -> { _: [], bar: 'true' }

Closes #27

@xxiaoxiong xxiaoxiong closed this May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flag without an alias is being reported as unknown

1 participant