Skip to content

Fix --help on a non-first subcommand showing wrong help (#586)#587

Open
Sootopolis wants to merge 1 commit into
zio:masterfrom
Sootopolis:sootopolis/subcommand-help-routing
Open

Fix --help on a non-first subcommand showing wrong help (#586)#587
Sootopolis wants to merge 1 commit into
zio:masterfrom
Sootopolis:sootopolis/subcommand-help-routing

Conversation

@Sootopolis

Copy link
Copy Markdown

Closes #586.

Problem

root <sub> --help showed the first registered subcommand's help instead of the named one, for every non-first subcommand (and nested cases). Root --help was fine.

Fix

Subcommands.parse parsed the child OrElse with the original conf (finalCheckBuiltIn = true) in the UserDefined branch. A non-matching alternative then ran exhaustiveSearch, returned its own help as a success, and short-circuited the OrElse before the named subcommand was tried. Switched that one call to the existing childConf (finalCheckBuiltIn = false) — already used in the sibling help/wizard paths in the same method — so a mismatch fails as CommandMismatch and OrElse advances to the correct subcommand.

Test

Added a regression test under the issue #448 suite: tool stop --help must show stop's help and not the first subcommand's. Verified RED on master (leaked the first subcommand's option) before the fix.

Platform Result
zioCliJVM/testOnly zio.cli.CommandSpec 38/38
zioCliJS/testOnly zio.cli.CommandSpec 38/38
zioCliNative/testOnly zio.cli.CommandSpec 38/38
sbt fmt / sbt check clean

Subcommands.parse passed the parent's CliConfig (finalCheckBuiltIn =
true) when parsing the child OrElse, so a non-matching alternative ran
exhaustiveSearch and returned its own help, short-circuiting before the
named subcommand was tried. Use childConf (finalCheckBuiltIn = false),
as the sibling help/wizard paths already do, so a mismatch fails as
CommandMismatch and OrElse advances to the correct subcommand.

Closes zio#586

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jun 5, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

--help on a non-first subcommand shows the first subcommand's help instead

2 participants