cli
cli copied to clipboard
fix: allow DefaultCommand to handle its own flags
Fixes #2249
Summary
- When DefaultCommand is set, flags defined on the default subcommand now work without specifying the subcommand name
- Previously, unknown flags were rejected during parent command parsing before default command routing
- Pass unknown flags through as positional args when DefaultCommand is set
Test plan
- [x] Added regression test TestDefaultCommandWithSubcommandFlags
- [x] All existing DefaultCommand tests pass
- [x] Full test suite passes
@dearchap Thanks for the review! I've addressed all three points in the latest push:
- L215 — Added
index == 0guard so only a fully-unknown flag triggers the DefaultCommand passthrough, not an unknown char mid-split - L5739 — Moved the assertion outside the action callback using an
actionExecutedguard variable - L5758 — Renamed
barflag tovalueto avoid confusion with the"bar"value
@dearchap Good catch - added actionRun guard to both TestDefaultCommandWithShortFlag and TestDefaultCommandWithShortFlagHandling in 68d38c4. The assertion now runs outside the action callback, matching the pattern in TestDefaultCommandWithSubcommandFlags.
@dearchap All review feedback has been addressed and CI is green. Could you take another look when you get a chance? Thanks!