Skip to content

fix: render help for <group> help subcommand form#15

Merged
jpage-godaddy merged 5 commits into
mainfrom
help-not-working
Jun 8, 2026
Merged

fix: render help for <group> help subcommand form#15
jpage-godaddy merged 5 commits into
mainfrom
help-not-working

Conversation

@jpage-godaddy

Copy link
Copy Markdown
Collaborator

Summary

<group> help (e.g. gddy auth help, gddy application help) was reported as broken: it returned unknown command "help" for "gddy auth" even though the group's help listing advertises a help command.

Root cause

The engine ships a curated root help command, so it calls .disable_help_subcommand(true) on the root. In clap v4 that setting propagates to every subcommand and cannot be re-enabled per child, so no group has a working help subcommand at parse time — yet the group help listing still shows one (it's rendered via render_long_help(), which builds the group in isolation and re-adds help). On top of that, a pre-flight check (unknown_group_command_message) reported the help token as an unknown command before clap ran.

Fix

Detect the <group> help [sub...] form in Cli::run and render the target's help directly, reusing the curated help-rendering path via a new shared render_help_for_parts helper. This matches clap's documented equivalence between cmd group help sub and cmd help group sub.

Scoped to groups (pure subcommand dispatch, so a help token there is unambiguously a help request). Leaf commands are left to clap so a literal help positional argument still parses, and <leaf> --help is unaffected.

Testing

  • Added cli_runtime_group_help_subcommand_renders_group_help (TDD: confirmed it fails before the fix, passes after). Covers <group> help and <group> help <sub>.
  • cargo fmt --check, clippy -D warnings, cargo doc -D warnings, full test suite + doctests all pass.
  • Verified end-to-end against the real gddy CLI (patched to this engine): gddy auth help, gddy application help, and gddy auth help status all render help with exit 0; root help, help auth, auth login --help, and the auth bogus unknown-command error are unaffected.

🤖 Generated with Claude Code

The engine ships a curated root `help` command and disables clap's
auto-generated help subcommand on the root. In clap v4 that setting
propagates to every subcommand and cannot be re-enabled per child, so
`<group> help` (e.g. `gddy auth help`) was rejected — even though the
group's help listing advertises a `help` entry. A pre-flight check also
reported the `help` token as an unknown command before clap ran.

Detect the `<group> help [sub...]` form in `Cli::run` and render the
target's help directly, reusing the curated help-rendering path via a
shared `render_help_for_parts` helper. Scoped to groups (pure subcommand
dispatch); leaf commands are left to clap so a literal `help` argument
still parses, and `<leaf> --help` is unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a mismatch between the CLI’s curated root help command and clap v4’s propagated disable_help_subcommand(true) behavior by detecting the <group> help [sub...] form at runtime and directly rendering the appropriate help output (equivalent to help <group> [sub...]), plus adds regression coverage.

Changes:

  • Add a preflight detector for <group> help [sub...] and route it to a shared render_help_for_parts helper.
  • Refactor root help <path> rendering to reuse the new shared helper.
  • Add a tokio integration test covering <group> help and <group> help <sub>.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/cli.rs Adds group-help detection in Cli::run, introduces render_help_for_parts, and implements group_help_target_parts.
tests/foundation.rs Adds regression test ensuring <group> help and <group> help <sub> render the expected help output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cli.rs Outdated
Comment thread src/cli.rs Outdated
Comment thread src/cli.rs Outdated
Comment thread tests/foundation.rs Outdated
- Route `<group> help` through the curated root `help` command (rewrite
  to `help <group> [sub...]`) so global-flag parsing and the `pre_run`
  hook run, matching `help <group>` and bare-group help.
- Defer to clap when a group defines its own real `help` subcommand, so
  a consumer-registered `help` command is dispatched instead of the shim.
- Compute the positional command path once and share it between the
  group-help rewrite and the unknown-command check.
- Reword the test comment to describe the engine-level help shim
  accurately (the root suppresses clap's auto-generated help subcommand).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread src/cli.rs
The previous rewrite reconstructed the argument vector from the command
path alone, dropping any global flags (e.g. `--output json`) so the
invocation was not truly equivalent to `help <group>`. Rewrite the
positional command tokens in place within the normalized clap args
instead: only the positional stream is reordered (`[group, help, sub]` ->
`[help, group, sub]`), while every flag — `key=value` forms,
value-consuming flags, unknown flags that consume a value, and anything
after `--` — is preserved in its original position. Add regression
coverage for a global flag before the group and a `key=value` flag after.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Positional tokens after a `--` separator are literal operands, not
command keywords, so the group-help shim must not treat a `help` among
them as a help request. Previously `<group> -- help` rendered the
group's help; now the `help` is left to clap as a literal (unknown)
subcommand, matching the documented meaning of `--`.

The guard counts the positionals preceding any `--` and only matches a
`help` token before that boundary, so `<group> help -- <sub>` (help
before the separator) still renders the subcommand's help.
Add coverage for `<group> <subgroup> help` and
`<group> <subgroup> help <leaf>`, exercising the group-help shim's
full prefix walk through a nested group.
@jpage-godaddy jpage-godaddy merged commit c21db13 into main Jun 8, 2026
2 checks passed
@jpage-godaddy jpage-godaddy deleted the help-not-working branch June 8, 2026 18:14
jpage-godaddy pushed a commit that referenced this pull request Jun 9, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.0](cli-engine-v0.1.3...cli-engine-v0.2.0)
(2026-06-09)


### ⚠ BREAKING CHANGES

* `CommandSpec.no_auth` (bool) is replaced by `CommandSpec.auth`
(`AuthRequirement`), and `MiddlewareRequest.no_auth` by
`MiddlewareRequest.auth`. `CommandContext.credential` is now a
`CredentialResolver` instead of `Option<Credential>`;
`RuntimeCommandSpec::new` and `new_typed` handler closures receive a
`CredentialResolver`; and `Authorizer::authorize` receives
`&CredentialResolver` instead of `Option<&Credential>`. The
`no_auth(true)` builder still works and maps to `AuthRequirement::None`;
`auth_optional()` and `auth(AuthRequirement)` select the other policies.

### Features

* fail-closed authentication via AuthRequirement; populate PKCE identity
([#17](#17))
([34313bf](34313bf))


### Bug Fixes

* render help for `<group> help` subcommand form
([#15](#15))
([c21db13](c21db13))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants