fix(parser): handle short alias with = syntax (-n=value)
Resolves #237
Problem
-n=John with short alias n for name returns { n: "=John", name: "=John" } instead of { n: "John", name: "John" }.
Root cause: node:util parseArgs does not handle -<char>=<value> syntax for short aliases. It treats -n=John as -n with value =John.
Fix
Two-part fix in src/_parser.ts:
-
Filter single-char aliases from
allOptionsβ aliases likenshould only be registered via theshortproperty of their target option, not as standalone options. OtherwiseparseArgsgets confused whennappears as both a full option and a short alias. -
Preprocess
-<char>=<value>syntax β before passing args toparseArgs, expand-n=Johnto--name=Johnwhennis a known alias forname. This bypasses theparseArgslimitation entirely.
Tests
- Existing
it.failstest now passes β changed toit - Added test: multiple short aliases with
=syntax - Added test: unknown short flag with
=passes through without crash - 19/19 tests pass β
Rebased
Rebased on latest main to resolve merge conflicts. The parser changes from upstream (alias coercion, type handling) are preserved β this PR now only adds the = syntax handling.
[!NOTE]
Reviews paused
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
- [ ] βΆοΈ Resume reviews
- [ ] π Trigger review
π Walkthrough
Walkthrough
Parser narrows registered options to long/multi-character names (booleans, strings, defaults, multi-char aliases), collects single-character short aliases separately, and adds type-aware coercion: "false" β false for booleans and boolean true β "" for string-declared options.
Changes
| Cohort / File(s) | Summary |
|---|---|
Parser core src/_parser.ts |
Adds isStringType, computes shortAliasNames from 1-char alias entries, restricts allOptions to long/multi-character keys (booleans/strings/defaults/multi-char aliases), and applies value coercion after parsing (string "false" β boolean false for booleans; boolean true β "" for string options). Alias propagation and --no- handling remain. |
Parser tests test/parser.test.ts |
Converts a previously failing alias test into a normal test; adds assertions for boolean coercion with --flag=true/false and for string-declared options receiving a bare --option (coerced to empty string, not boolean). |
Estimated code review effort
π― 3 (Moderate) | β±οΈ ~20 minutes
Possibly related PRs
- unjs/citty#230: Related short-option/alias parsing with
=behavior and tests for-f=barstyle inputs. - unjs/citty#239: Related parser logic changes around type-aware coercion and alias handling.
Suggested reviewers
- pi0
Poem
π° I nibble dashes, hop through names,
Short hops point where long flags claim.
"false" unmasked, booleans set right,
Strings stay strings in moonlit night.
π₯
π₯ Pre-merge checks | β 4 | β 1
β Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | β οΈ Warning | Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |
β Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | β Passed | The title accurately summarizes the main change: fixing the parser to handle short aliases with the equals syntax (e.g., -n=value). |
| Linked Issues check | β Passed | The PR successfully addresses issue #237 by excluding single-character alias keys from full option registration and ensuring values are correctly propagated to long options. |
| Out of Scope Changes check | β Passed | All changes in the parser and tests directly relate to fixing the short alias with equals syntax issue; no out-of-scope changes detected. |
| Description Check | β Passed | Check skipped - CodeRabbitβs high-level summary is enabled. |
βοΈ Tip: You can configure your own custom pre-merge checks in the settings.
β¨ Finishing Touches
π§ͺ Generate unit tests (beta)
- [ ] Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
Can you please add tests?
Done! Changed it.fails to it (the fix makes the existing test pass) and added two more edge case tests:
- Short alias with
=for boolean flags (-v=true) - Multiple short aliases in the same call
Updated to latest upstream code. The parser fix filters single-char aliases from allOptions so they are only registered via short property. Test changed from it.fails to it.
@pi0 Done! I rebased onto the latest main β the it.fails now passes, and I added two more edge case tests:
- Multiple short aliases with
=syntax (-n=John -a=admin) - Unknown short flag with
=β passes through without crash
19/19 tests pass. Also squashed the previous messy commit history into a clean single commit.