Skip to content

fix(cli): hand --help/-h to the wrapped tool on every forwarding subcommand - #3944

Closed
kylehgc wants to merge 1 commit into
rtk-ai:developfrom
kylehgc:submit/wrapped-tool-help-flag
Closed

kylehgc wants to merge 1 commit into
rtk-ai:developfrom
kylehgc:submit/wrapped-tool-help-flag

Conversation

@kylehgc

@kylehgc kylehgc commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Problem

clap's auto-generated -h/--help (and its auto help subcommand) is live on every wrapped-tool subcommand, so rtk <tool> --help prints rtk's one-paragraph stub for the subcommand instead of running the tool. Through the hook, a user or agent that types tsc --help, cargo build --help, git show -h, npm --help or docker --help gets rtk's doc line back; the tool's own help is unreachable except as rtk <tool> -- --help. Only Psql and Ctest had opted out per variant.

$ rtk tsc --help
TypeScript compiler with grouped error output

Usage: rtk tsc [OPTIONS] [ARGS]...

$ rtk cargo build --help
Build with compact output (strip Compiling lines, keep errors)

Usage: rtk cargo build [OPTIONS] [ARGS]...

Fix

One rule instead of ~100 attributes. After building the derived Cli, forward_help_to_wrapped_tools walks the command tree and disables clap's help flag on every subcommand that carries a trailing-var-arg positional; main parses from that command (parse_cli). Exemptions are exact:

  • rtk's own entry points keep clap's help: RTK_META_COMMANDS plus err/test/summary/format (they take a trailing command but run it themselves), and everything beneath them (rtk hook check --help).
  • The 16 parents whose passthrough is an external_subcommand arm (git, cargo, docker + compose, pnpm, dotnet, kubectl, oc, prisma + migrate, bun + pm, deno, go, sbt, gt) are not visible to the walk before clap builds, so they carry #[command(disable_help_flag = true, disable_help_subcommand = true)]. Both settings propagate to the subtree; the second keeps rtk git help log from being rtk's stub.
  • test_every_wrapped_tool_subcommand_forwards_help builds the command and holds both groups to one invariant (≥100 forwarding subcommands seen; a parent counts as forwarding when any child does).

A forwarded --help then has to reach the tool's passthrough, not its filter: a filter models the tool's normal output and reads usage text as an empty run (cargo build --help → "cargo build (0 crates compiled)", git worktree -h listed worktrees, wget <url> --help → " ok | …"). Three shared guards instead of one per filter:

  • core::runner::run flips to RunMode::Passthrough when --help (or -h, except for tools that define it otherwise: psql -h host, ls/tree -h human sizes, grep -h no-filename) appears before any --. The npx [--no-install] -- / pnpm exec -- / yarn exec -- prefix rtk itself inserts for a Node tool not on PATH (utils::tool_exec) is skipped; the tool's argv starts after it.
  • core::stream::capture shows the usage verbatim and exits with the tool's code (git: 129).
  • git::run treats -h/--help before -- as a passthrough request, with clap's stripped -- restored (and stash's own operand rejoined first) so git log -- -h stays a pathspec.
  • find's dispatcher sends -help/--help down its existing verbatim path (GNU find has no -h).

Tests

  • src/main.rs: parse_cli tests for tsc --help/-h, grep --max-len 40 --help, nested git log --help, git --help / git help log / git bisect --help past the external arm, meta commands keeping DisplayHelp; the total contract walk. Two existing tests moved from Cli::try_parse_from to parse_cli so they exercise the parser main actually runs.
  • src/core/runner.rs: requests_help reads the tool's own flags before --; -h belongs to psql/ls/tree/grep (ripgrep's -h is help, -I is no-filename); rtk's package-runner prefix is skipped and the user's own later -- still ends the scan.
  • src/cmds/git/git.rs: -h/--help before -- only; stash's operand rejoins the user region before restore_double_dash.
  • src/cmds/system/find_cmd.rs: --help/-help dispatch verbatim; -h is not a find flag.
  • tests/stderr_only_failure_test.rs (unix) and tests/help_forwarding_windows_test.rs (windows, .cmd shims): with fake tools on PATH, cargo build --help (filtered runner), wget <url> --help (capture, exit code kept), playwright test --help through a fake npx (package-runner prefix), pytest -h (help), psql -h host (stays filtered), git log -h/git status -h (git's stdout usage, exit 129), git log -- -h (pathspec). Each was verified to fail with its guard reverted.

Gate: cargo fmt --all --check, cargo clippy --all-targets (zero warnings), cargo test --all green.

Out of scope

  • --version is not a twin: clap's version flag lives on the top-level Cli only; rtk tsc --version already reaches tsc.
  • Whether a tool's help renders well is the tool's output; help never reaches a filter now.
  • run_stash drops a -- before its first operand on its own (git stash -- x → git stash push x); pre-existing and unchanged.

🤖 Generated with Claude Code

…ommand

clap's auto help (flag and `help` subcommand) was live on ~100 wrapped-tool
subcommands, so `rtk tsc --help` (and, through the hook, `tsc --help`)
printed rtk's one-line stub instead of running the tool. Only Psql and
Ctest had opted out per variant.

One rule instead of a hundred attributes: after building the derived
command, disable clap's help flag on every subcommand that carries a
trailing-var-arg positional, recursively, and parse from that. rtk's own
entry points (meta commands, and err/test/summary/format which run a
trailing command themselves) keep clap's help. The 16 parents whose
passthrough is an external_subcommand arm are not visible before clap
builds, so they carry disable_help_flag + disable_help_subcommand on the
variant; a contract test builds the command and holds both groups to one
invariant.

A forwarded --help must reach the tool's passthrough, not its filter: a
filter models the tool's normal output and read usage as an empty run
(`cargo build --help` -> "0 crates compiled", `git worktree -h` listed
worktrees). Three shared guards: runner::run flips to Passthrough on
--help (or -h, except for psql/ls/tree/grep which define it) before any
--, skipping the `npx [--no-install] --` / `pnpm exec --` prefix rtk
inserts for a Node tool not on PATH; stream::capture shows the usage
verbatim and exits with the tool's code; git's entry treats -h/--help
before -- as passthrough, with clap's stripped -- restored so
`git log -- -h` stays a pathspec. find's dispatcher sends -help/--help
down its verbatim path.

Each guard has a test that fails without it, on unix and Windows.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes rtk's help-forwarding bug where clap's auto-generated -h/--help intercepted calls on wrapped-tool subcommands, showing rtk's stub description instead of the wrapped tool's own help. Replaces ~100 per-variant opt-outs with a single tree-walking rule that disables clap's help flag on subcommands with trailing-var-arg positionals, plus exemptions for external-subcommand tools and shared passthrough guards in the runner, stream capture, git, and find dispatch paths.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@KuSh

KuSh commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for the groundwork. I'm closing it as superseded by #4348, which takes the same approach: one walk over the clap tree that releases -h/--help/help on every forwarding subcommand, plus a check so the filter doesn't summarise the page the tool prints. The PR body there credits this one. The review of #4348 found handlers that run the child through exec_capture without that check (pnpm, wget among them). Your placement of the check inside stream::capture, which covers every caller at once, is offered there as one way to close it.

@KuSh KuSh closed this Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants