fix: pass option values to subcommands verbatim - #6
Merged
Merged
Conversation
A parent command only tells mri about the options it declares itself, so every option belonging to a subcommand fell through to mri's numeric coercion on the way past. `--title ""` parsed as the number 0, `--title 007` as 7, `--title 1e3` as 1000. `reconstructArgv` then stringified those values back into an argv for the subcommand, which received `--title 0` with no way to know it had ever been anything else. The coercion is not reversible, so the fix is not to serialize through it. The subcommand now receives the original tokens, minus this command's own options and the subcommand name — only the subcommand knows the types of its own options, so it should see exactly what the user typed. A flat command was never affected, because it declares its own options to mri and never goes through the reconstruction. That asymmetry is what made this hard to see: the same option block behaves differently depending on whether it sits under a subcommand. Clustered short groups like `-abc` are passed through rather than guessed at. Swallowing a flag and the token after it on a wrong guess is a worse failure than the subcommand reporting an unknown option. Co-Authored-By: Claude Opus 5 (1M context) <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.
Problem
A parent command only tells mri about the options it declares, so every option belonging to a subcommand fell through to mri's numeric coercion on the way past:
--title ""parsed as the number0--title 007parsed as7--title 1e3parsed as1000reconstructArgvthen stringified those coerced values back into an argv for the subcommand, so the subcommand received--title 0with no way to know the value had ever been anything else.A flat command was never affected — it declares its own options to mri and never goes through the reconstruction. That asymmetry is what made this hard to spot: the same option block behaves differently depending on whether it sits under a subcommand.
Fix
The coercion isn't reversible, so the fix is to not serialize through it at all.
reconstructArgvis replaced byargvForSubcommand, which hands the subcommand the original tokens, minus this command's own options and the subcommand name. Only the subcommand knows the types of its own options, so it should see exactly what the user typed.Details:
--opt=valuecarries its own value;--opt valueconsumes the next token, but only when the option actually takes one.--is passed through verbatim.inheritedOptionsas before.-abcare passed through rather than guessed at — swallowing a flag and the token after it on a wrong guess is a worse failure than the subcommand reporting an unknown option.Tests
New
option values reach subcommands verbatimblock covering empty strings, numeric-looking strings (007,1e3,0x10,1.50,+5), parity with the flat-command path, inherited parent options, and--opt=value/ boolean flags.bun test— 278 pass, 0 fail.bun run typecheckclean.🤖 Generated with Claude Code