Repository navigation
Conversation
…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]>
📊 Automated PR Analysis
SummaryFixes 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
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
|
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 |
Problem
clap's auto-generated
-h/--help(and its autohelpsubcommand) is live on every wrapped-tool subcommand, sortk <tool> --helpprints rtk's one-paragraph stub for the subcommand instead of running the tool. Through the hook, a user or agent that typestsc --help,cargo build --help,git show -h,npm --helpordocker --helpgets rtk's doc line back; the tool's own help is unreachable except asrtk <tool> -- --help. OnlyPsqlandCtesthad opted out per variant.Fix
One rule instead of ~100 attributes. After building the derived
Cli,forward_help_to_wrapped_toolswalks the command tree and disables clap's help flag on every subcommand that carries a trailing-var-arg positional;mainparses from that command (parse_cli). Exemptions are exact:RTK_META_COMMANDSpluserr/test/summary/format(they take a trailing command but run it themselves), and everything beneath them (rtk hook check --help).external_subcommandarm (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 keepsrtk git help logfrom being rtk's stub.test_every_wrapped_tool_subcommand_forwards_helpbuilds the command and holds both groups to one invariant (≥100 forwarding subcommands seen; a parent counts as forwarding when any child does).A forwarded
--helpthen 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 -hlisted worktrees,wget <url> --help→ " ok | …"). Three shared guards instead of one per filter:core::runner::runflips toRunMode::Passthroughwhen--help(or-h, except for tools that define it otherwise:psql -h host,ls/tree -hhuman sizes,grep -hno-filename) appears before any--. Thenpx [--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::captureshows the usage verbatim and exits with the tool's code (git: 129).git::runtreats-h/--helpbefore--as a passthrough request, with clap's stripped--restored (and stash's own operand rejoined first) sogit log -- -hstays a pathspec.find's dispatcher sends-help/--helpdown its existing verbatim path (GNU find has no-h).Tests
src/main.rs:parse_clitests fortsc --help/-h,grep --max-len 40 --help, nestedgit log --help,git --help/git help log/git bisect --helppast the external arm, meta commands keepingDisplayHelp; the total contract walk. Two existing tests moved fromCli::try_parse_fromtoparse_cliso they exercise the parsermainactually runs.src/core/runner.rs:requests_helpreads the tool's own flags before--;-hbelongs topsql/ls/tree/grep(ripgrep's-his help,-Iis 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/--helpbefore--only; stash's operand rejoins the user region beforerestore_double_dash.src/cmds/system/find_cmd.rs:--help/-helpdispatch verbatim;-his not a find flag.tests/stderr_only_failure_test.rs(unix) andtests/help_forwarding_windows_test.rs(windows,.cmdshims): with fake tools on PATH,cargo build --help(filtered runner),wget <url> --help(capture, exit code kept),playwright test --helpthrough a fakenpx(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 --allgreen.Out of scope
--versionis not a twin: clap's version flag lives on the top-levelClionly;rtk tsc --versionalready reaches tsc.run_stashdrops a--before its first operand on its own (git stash -- x→git stash push x); pre-existing and unchanged.🤖 Generated with Claude Code