Skip to content

fix(roar): fix positional argument parsing when mixed with flags#863

Merged
YusukeHirao merged 4 commits intodevfrom
claude/fix-positional-args-parsing-asnck
Mar 13, 2026
Merged

fix(roar): fix positional argument parsing when mixed with flags#863
YusukeHirao merged 4 commits intodevfrom
claude/fix-positional-args-parsing-asnck

Conversation

@YusukeHirao
Copy link
Copy Markdown
Member

@YusukeHirao YusukeHirao commented Mar 13, 2026

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

  • Modified parseFlags function signature and return type: Changed from returning only InferFlags<F> to returning an object with both flags and args properties, allowing positional arguments to be captured alongside flag values
  • Unified positional argument extraction: Consolidated positional argument parsing into the parseFlags function to ensure consistent handling whether flags are defined or not
  • Updated parseCli function: Simplified the logic for extracting both flags and positional arguments by using the new return structure from parseFlags
  • Added comprehensive test coverage: Added 5 new test cases covering:
    • Boolean flags preceding positional arguments
    • Short flag variants with positional arguments
    • Multiple mixed flags and positional arguments
    • Commands without flags
    • Arguments after -- separator (treated as positional)
  • Updated documentation: Added a new section in README explaining how flags and positional arguments can be mixed in any order, with practical examples

Implementation Details

The fix ensures that yargs-parser correctly identifies positional arguments (stored in the _ property) even when boolean flags are present. By consolidating the parsing logic into parseFlags, we guarantee consistent behavior across all command configurations.

https://claude.ai/code/session_01RVZyxQmo5qFTP6jYsAuaGF

claude added 4 commits March 13, 2026 02:22
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
@YusukeHirao YusukeHirao changed the title Fix positional argument parsing when mixed with flags fix(roar): fix positional argument parsing when mixed with flags Mar 13, 2026
@YusukeHirao YusukeHirao merged commit 1aaf349 into dev Mar 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parseCli: positional args lost when boolean flag precedes them

2 participants