fix(option): register kebab-case names with the parser#169
Open
MukundaKatta wants to merge 1 commit intocacjs:mainfrom
Open
fix(option): register kebab-case names with the parser#169MukundaKatta wants to merge 1 commit intocacjs:mainfrom
MukundaKatta wants to merge 1 commit intocacjs:mainfrom
Conversation
Option names were stored only in their camelCased form, so the
underlying mri parser never learned that the original kebab form (e.g.
`include-locked`) was a boolean flag or an alias of the camelCase one.
Two user-visible bugs followed:
- `--include-locked latest` was parsed as `{ includeLocked: 'latest' }`
with `latest` removed from the positional args, instead of as a
boolean with `latest` left untouched.
- Long hyphenated aliases (e.g. `--clear-screen` aliased to `-c` /
`--clear`) didn't propagate the value back to the camelCased and
short-flag aliases.
Track the original (pre-camelcase) names on `Option.rawNames` and
register both the camelCased and kebab-case forms with mri's `alias`
and `boolean` arrays.
Fixes cacjs#119
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Option names were only stored in their camelCased form, so the underlying mri parser never learned that the original kebab form (e.g.
include-locked) was a boolean flag, nor that it aliased the camelCase one.This produced two user-visible bugs:
1. Kebab-case boolean options swallowed the next positional arg
2. Long hyphenated aliases didn't propagate (#119)
Fix
Optionnow tracks the original (pre-camelcase) names onrawNames, andgetMriOptionsregisters both the camelCased and kebab-case forms in mri'saliasandbooleanarrays. The canonical name (used as the alias key) is still the shortest entry, preserving existing alias-key behavior.Test plan
pnpm vitest run— 19 tests pass (2 new):pnpm lintpnpm exec tsdown— clean build, manual smoke-tested all four invocation formsDownstream impact
This also fixes antfu/taze#187 (
--include-lockedand-lwork differently) and similar bugs in any cac-based CLI that uses kebab-case boolean options.Fixes #119