fix(roar): fix positional argument parsing when mixed with flags#863
Merged
YusukeHirao merged 4 commits intodevfrom Mar 13, 2026
Merged
fix(roar): fix positional argument parsing when mixed with flags#863YusukeHirao merged 4 commits intodevfrom
YusukeHirao merged 4 commits intodevfrom
Conversation
The second yargsParser call for extracting positional args lacked flag type definitions, so boolean flags consumed the next token as their value instead of leaving it as a positional argument. Unified parsing into a single yargsParser call within parseFlags to return both typed flags and positional args together. Closes #862 https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF
- Use yargsParser for flagless commands to maintain consistent arg parsing behavior (unknown flags are not included as positional args) - Add expect(result.command) before conditional flag assertions to prevent silent test skips - Add test for flagless command with positional args - Add test for -- separator handling https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF
Document that flags and positional args can be mixed in any order, including boolean flags preceding positional args and -- separator. https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF
- Update parseFlags @returns to reflect new { flags, args } return type - Fix InferFlags JSDoc reference from internal parseFlags to RoarResult - Fix README bash examples that incorrectly stated different inputs produce the same result - Fix onError description to include unknown command case https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF
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
Fixed a bug in the CLI argument parser where positional arguments were not being correctly preserved when boolean flags preceded them. The parser now properly handles mixed flag and positional argument ordering.
closes: #862
Key Changes
parseFlagsfunction signature and return type: Changed from returning onlyInferFlags<F>to returning an object with bothflagsandargsproperties, allowing positional arguments to be captured alongside flag valuesparseFlagsfunction to ensure consistent handling whether flags are defined or notparseClifunction: Simplified the logic for extracting both flags and positional arguments by using the new return structure fromparseFlags--separator (treated as positional)Implementation Details
The fix ensures that
yargs-parsercorrectly identifies positional arguments (stored in the_property) even when boolean flags are present. By consolidating the parsing logic intoparseFlags, we guarantee consistent behavior across all command configurations.https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF