Skip to content

fix(grep): treat -h as --no-filename instead of clap help - #3888

Closed
dmazhukov wants to merge 1 commit into
rtk-ai:developfrom
dmazhukov:fix/grep-h-no-filename
Closed

dmazhukov wants to merge 1 commit into
rtk-ai:developfrom
dmazhukov:fix/grep-h-no-filename

Conversation

@dmazhukov

@dmazhukov dmazhukov commented Sep 6, 2026 •

Copy link
Copy Markdown

Refs #3663 (the -h part; -l/-m/-t are already long-only on develop).

Summary

rtk grep -h PATTERN FILES still prints rtk's usage text on develop: clap's auto help flag captures -h before search.rs, which already reads it as grep's --no-filename (and as help for rg only), ever sees it. Agents piping grep -ho ... | sort | uniq -c get the help screen and fall back to rtk proxy grep.

This disables clap's help flag on the Grep subcommand (same precedent as Psql). --help still reaches the engine through search.rs. Rebased on current develop: the filename handling from the first version is dropped, since develop now does it in search.rs.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • dash_h_is_no_filename_not_help in tests/grep_faithful_format_test.rs pins -h, -ho and -H against real grep byte for byte

Side note, not addressed here: with -h -H together develop follows GNU grep (last flag wins, filename shown), while BSD grep on macOS lets -h win regardless of order.

@CLAassistant

CLAassistant commented Sep 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

`rtk grep -h PATTERN FILES` printed rtk's own usage text: clap's auto help
flag captured `-h` before search.rs, which already reads it as grep's
--no-filename (and as help for rg only), could see it. Agents piping
`grep -ho ... | sort | uniq -c` got the help screen and fell back to
`rtk proxy grep`.

Disable clap's help flag on the Grep subcommand; `--help` still reaches
the engine through search.rs. The integration test pins `-h`, `-ho`
and `-H` against real grep byte for byte.
@KuSh

KuSh commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for pinning the -ho cluster. I'm closing it as superseded by #4348, which releases clap's help flag on every wrapper subcommand. On its head, rtk grep -h, -ho and -hn match grep byte for byte, and --help still reaches grep.

@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.

3 participants