Skip to content

Fix --help/--wizard showing wrong subcommand help (#448) — review follow-up#576

Merged
hearnadam merged 3 commits into
zio:masterfrom
guersam:subcommand-help-followup
May 11, 2026
Merged

Fix --help/--wizard showing wrong subcommand help (#448) — review follow-up#576
hearnadam merged 3 commits into
zio:masterfrom
guersam:subcommand-help-followup

Conversation

@guersam
Copy link
Copy Markdown
Contributor

@guersam guersam commented May 7, 2026

Continues #559 by @tjarvstrand. The original fix is unchanged; this PR adds the refactor requested in the review thread (#559 (comment)) plus closely-related cleanups, so credit for the fix stays with the original author.

Commits

  1. eb68646 (tjarvstrand) — original fix for Built in args like --help in Subcommand was unexpected behavior #448, unchanged.
  2. Consolidate NoBuiltInMatch error and cover leftover case — addresses the review feedback on parseBuiltInArgs:
    • Replaces the new if (leftover.nonEmpty) ... else ZIO.fromOption(value).mapError(...) with ZIO#collect(noBuiltInMatch) { case (_, Nil, Some(value)) => CommandDirective.BuiltIn(value) }, matching the style already used in Subcommands#parse. Also folds the .map(BuiltIn) step into the partial function.
    • Drops the unnecessary s interpolator on the error message (per the original Copilot note).
    • Declares noBuiltInMatch as def rather than val. Both consumers (ZIO#collect's e: => E1 and ZIO.fail's error: => E) take their failure by-name, so def defers allocation to the failure path while keeping the descriptive name.
    • Adds two regression tests for the consolidated leftover.nonEmpty branch (cmd --help payload and cmd --wizard payload must not be consumed as built-in directives). The --help variant was first verified RED on master (returned "help" instead of "user") before being committed.
  3. Share childConf and invalidArgument in Subcommands.parse — both helpDirectiveForChild and wizardDirectiveForChild constructed the same conf.copy(finalCheckBuiltIn = false) and the same ValidationError(InvalidArgument, HelpDoc.empty). Hoisted to shared local definitions to keep the two branches in lockstep. invalidArgument is def for the same by-name reason as above; childConf stays val since child.parse takes its config strictly.

Behavior

Pure refactor — no behavior change.

Platform Result
zioCliJVM/testOnly zio.cli.CommandSpec 37/37
zioCliJS/testOnly zio.cli.CommandSpec 37/37
zioCliNative/testOnly zio.cli.CommandSpec 37/37
scalafmtCheckAll clean

Closes #448 if merged.

@guersam guersam force-pushed the subcommand-help-followup branch 2 times, most recently from 6a309ad to 068911b Compare May 7, 2026 07:05
guersam and others added 2 commits May 7, 2026 16:47
Address review feedback on zio#559:

- Extract the duplicated ValidationError into a local val.
- Replace the if/else in parseBuiltInArgs with ZIO#collect, which
  matches the style used in Subcommands#parse and folds the
  Some(value)/leftover.isEmpty success and the failure into a
  single partial function.
- Add a regression test covering the leftover.nonEmpty branch
  directly: 'cmd --help payload' must not be consumed as a
  built-in directive.

Co-authored-by: Thomas Järvstrand <tjarvstrand@gmail.com>
Both helpDirectiveForChild and wizardDirectiveForChild constructed
the same conf.copy(finalCheckBuiltIn = false) and the same
ValidationError(InvalidArgument, HelpDoc.empty). Hoist them to
shared local vals to keep the two branches in lockstep.

Co-authored-by: Thomas Järvstrand <tjarvstrand@gmail.com>
@guersam guersam force-pushed the subcommand-help-followup branch from 068911b to b75c735 Compare May 7, 2026 07:51
@guersam guersam marked this pull request as ready for review May 7, 2026 07:51
@guizmaii guizmaii requested a review from hearnadam May 7, 2026 09:27
@tjarvstrand
Copy link
Copy Markdown
Contributor

Sorry for dropping the ball on this! Thanks for picking it up!

@hearnadam hearnadam merged commit b426a2a into zio:master May 11, 2026
23 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.

Built in args like --help in Subcommand was unexpected behavior

3 participants