Skip to content

fix(search): stop clap from capturing -h on rtk grep and rtk rg - #3905

Closed
AngelVRodC wants to merge 1 commit into
rtk-ai:developfrom
AngelVRodC:fix/search-flag-correctness
Closed

AngelVRodC wants to merge 1 commit into
rtk-ai:developfrom
AngelVRodC:fix/search-flag-correctness

Conversation

@AngelVRodC

@AngelVRodC AngelVRodC commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

rtk grep -h pattern file never searched: clap's auto-generated help flag intercepted -h before search.rs could classify it, so rtk printed its own help and exited 0 — a silent false negative. An agent consuming rtk's output sees no matches and no error, and moves on believing the pattern isn't there.

The sibling collisions in #3663 (-l, -m, -t) were already resolved on develop by making rtk's own options long-only. -h outlived them because it was clap's auto-generated help flag rather than a declared option, so dropping a short wasn't possible.

Verified on current develop (d402152): the repro still fires. rtk rg -h is affected the same way — there -h genuinely is rg's --help, but clap prints rtk's help instead of forwarding it.

Fix

#[command(disable_help_flag = true)] on Commands::Grep and Commands::Rg in src/main.rs — 9 lines, comments included.

This removes clap's handling of both -h and --help for those two subcommands. The per-engine check already in search::run then sees the flag and forwards the argv to the engine verbatim:

Command Before After
rtk grep -h alpha a.txt rtk's help, exit 0 alpha, exit 0
rtk grep --help rtk's help engine's help, forwarded
rtk rg -h rtk's help rg's help, forwarded

Psql and Ctest already carry the same attribute on develop; this applies the established pattern where the same collision exists.

Why so small

This PR previously contained a full per-engine flag-classification rewrite of search.rs (4 commits, ~900 lines). While it sat open, upstream merged that capability via #3988/#3998's arg_tokenizer work — grep_takes_value/rg_takes_value per-engine tables cover the -f, -r, -E, -D, --label, --color fixes this branch originally shipped. Rebased on develop, only the clap -h interception remains unfixed upstream, so the branch was shrunk to exactly that. The old scope is closed; #3665, #3161 and #3881 are resolved by the code already on develop.

Verification

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all — clean, 3781 passing
  • Repros above verified against native grep 2.6.0-FreeBSD / ripgrep 15.2.0 on macOS (stdout + exit code)
  • Common path untouched: rtk rg -n pattern src/ still emits grouped/capped output

Closes #3663

@CLAassistant

CLAassistant commented Sep 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

clap's auto-generated help flag intercepted -h before search.rs could
classify it, so `rtk grep -h pattern file` printed rtk's help instead of
searching — a silent false negative (exit 0, no matches shown).

disable_help_flag removes clap's handling of BOTH -h and --help; the
per-engine check in search::run then forwards either form to the engine
verbatim. Psql and Ctest already use the same attribute.
@AngelVRodC
AngelVRodC force-pushed the fix/search-flag-correctness branch from bb691d9 to ea69fff Compare September 14, 2026 01:17
@AngelVRodC AngelVRodC changed the title fix(search): classify grep/rg flags per engine instead of guessing fix(search): stop clap from capturing -h on rtk grep and rtk rg Sep 14, 2026
@KuSh

KuSh commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this. I'm closing it as superseded by #4348, which releases clap's help flag on every wrapper subcommand, grep and rg included. On its head, rtk grep -h alpha a.txt b.txt matches grep byte for byte, and rtk rg -h returns rg's own help.

@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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk grep claims -h, -l, -m and -t, which belong to grep/rg

3 participants