Repository navigation
fix: keep raw value for options with type: [String] - #178
Closed
iamhuman-cheolheelee wants to merge 1 commit into
Closed
iamhuman-cheolheelee wants to merge 1 commit into
iamhuman-cheolheelee wants to merge 1 commit into
Conversation
Closes #165 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #165 (the
type: [String]part; see note below)Root cause
src/cac.ts:282runsmri(argv, mriOptions)before thetypetransform. mri turns any numeric-looking value into a number (+310000->310000,01234->1234), and only after that doessetByType(src/utils.ts:126) callString(value). The original text is already lost, sotype: [String]can't bring it back.getMriOptions(src/utils.ts:51) never filled mri'sstringlist.Fix
getMriOptionsnow adds every name of an option that takes a value and hastype: [String]to mri'sstringlist, so mri keeps the argv text as-is. The existing transform still wraps it in an array.Invariant: when an option is declared with
type: [String], each value it produces is exactly the argv string the user passed.Names come from
rawName(the same kebab form mri sees), so--phone-numberand short aliases are covered too.Edge cases covered
01234), leading+, exponent (1e3), hex (0x10)-p)type, or withtype: [], still get mri's numeric coercion (no behavior change)Behavior change: an optional
[value]option withtype: [String]passed without a value now gives['']instead of['true'](that's mri's string semantics). Boolean flags aren't affected.Cost: one extra loop over the option names when building the mri options, O(options). Nothing new on the per-argument path.
Testing
array types with String transformFunction keep raw valuesintests/index.test.ts. It fails onmain(['310000']) and passes with the fix.pnpm vitest run18/18,pnpm lintclean,pnpm typecheckclean.Notes
Quoting in the shell (
-c "1234") never reaches the program, so an option without atypecan't tell a quoted value from an unquoted one.type: [String]is how a user opts in to raw strings, and that's the case this PR fixes.AI-assisted: I used Claude Code while investigating; I reviewed, ran and verified every change myself.
cc @peetzweg @sxzz