cli icon indicating copy to clipboard operation
cli copied to clipboard

fix: allow DefaultCommand to handle its own flags

Open lihan3238 opened this issue 6 months ago • 3 comments

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

lihan3238 avatar May 08 '26 19:05 lihan3238

@dearchap Thanks for the review! I've addressed all three points in the latest push:

  1. L215 — Added index == 0 guard so only a fully-unknown flag triggers the DefaultCommand passthrough, not an unknown char mid-split
  2. L5739 — Moved the assertion outside the action callback using an actionExecuted guard variable
  3. L5758 — Renamed bar flag to value to avoid confusion with the "bar" value

lihan3238 avatar May 16 '26 09:05 lihan3238

@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.

lihan3238 avatar May 16 '26 15:05 lihan3238

@dearchap All review feedback has been addressed and CI is green. Could you take another look when you get a chance? Thanks!

lihan3238 avatar May 18 '26 13:05 lihan3238