Repository navigation
Fail a value option followed by a switch instead of taking the switch as its value [patch] - #43
Merged
Conversation
… as its value [patch] TryTakeValue took the next argument as the option's value without looking at it, so a forgotten value swallowed the next switch: "--reason --display" recorded the reason "--display" and dropped the flag, and "-r --status" started a run instead of reporting status. When the next argument is a standard alias or an application option's alias, parsing now fails with "'--reason' needs a value." and the run exits 2. Values that only start with '-', such as "-" or "-5", are still taken. --for gets the same check. Fixes #38 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011eecgtNA1yFm2UXzPrxvEg
|
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 #38
What changed
CommandLineParser.TryTakeValuetookargs[index + 1]as the option's value without checking it. A forgotten value therefore swallowed the next switch, with no error:--reason --displayrecorded the reason"--display"and dropped the flag.-r --statusstarted a keep-awake run instead of printing the status report.Now, if the next argument is a standard alias (
StandardAliases) or an alias of a registered application option, parsing fails with'--reason' needs a value.andRunAsyncexits 2, the same as every other command-line mistake. Values that only start with-but aren't a known switch, such as-or-5, are still accepted.--forgoes through the sameTryTakeValue, so--for --statusnow reports the missing value. Before, it gave the misleading "'--status' is not a duration."Tests
TryParse_WithAnApplicationValueOptionFollowedByASwitch_Fails…covers--display,-d,--statusand-t.TryParse_WithADurationFollowedByASwitch_SaysTheValueIsMissing.TryParse_WithAValueThatIsNotAKnownSwitch_TakesItcovers-,-5andsome text.RunAsync_WithAValueOptionMissingItsValueBeforeStatus_ExitsTwochecks that the run exits 2 andOnStartnever runs. It passes--no-tray --for 0.05sso that, if the bug comes back, the test fails quickly instead of hanging in a run that never ends.🤖 Generated with Claude Code
https://claude.ai/code/session_011eecgtNA1yFm2UXzPrxvEg
Generated by Claude Code