Fix --help/--wizard showing wrong subcommand help (#448)#559
Fix --help/--wizard showing wrong subcommand help (#448)#559tjarvstrand wants to merge 1 commit intozio:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a parsing edge case where invoking --help / --wizard at the root command level incorrectly displayed help/wizard output for a child subcommand when subcommands are present.
Changes:
- Added regression tests covering root-level
--help/-hand--wizardbehavior when subcommands exist (issue #448). - Adjusted subcommand parsing so that the “final built-in option check” is disabled when probing child commands for help/wizard, preventing accidental selection of a child’s built-in help when no subcommand name is provided.
- Tightened built-in option parsing to reject matches when non-option leftover args remain after built-in option validation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
zio-cli/shared/src/test/scala/zio/cli/CommandSpec.scala |
Adds regression coverage ensuring root help/wizard prefers the parent command, while subcommand help still works. |
zio-cli/shared/src/main/scala/zio/cli/Command.scala |
Fixes root --help/--wizard behavior by disabling final built-in checks while probing child commands, preventing incorrect child help selection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .flatMap { case (_, leftover, value) => | ||
| if (leftover.nonEmpty) | ||
| ZIO.fail( | ||
| ValidationError( | ||
| ValidationErrorType.NoBuiltInMatch, | ||
| HelpDoc.p(s"No built-in option was matched") | ||
| ) | ||
| ) | ||
| else | ||
| ZIO | ||
| .fromOption(value) | ||
| .mapError(_ => | ||
| ValidationError( | ||
| ValidationErrorType.NoBuiltInMatch, | ||
| HelpDoc.p(s"No built-in option was matched") | ||
| ) | ||
| ) |
There was a problem hiding this comment.
In parseBuiltInArgs, the same ValidationError(NoBuiltInMatch, HelpDoc.p("No built-in option was matched")) is constructed in multiple branches. Consider extracting it into a local val and reusing it (and you can also drop the unnecessary s interpolator) to avoid duplication and reduce the chance of the branches drifting over time.
There was a problem hiding this comment.
@copilot fix this using a single match, like:
value match {
case Some(value) if leftover.isEmpty => Exit.succeed(value)
case _ => ZIO.fail(...)
No description provided.