Repository navigation
fix(grep): disable help flag to allow -h passthrough - #2532
Closed
axelray-dev wants to merge 1 commit into
Closed
axelray-dev wants to merge 1 commit into
axelray-dev wants to merge 1 commit into
Conversation
Add #[command(disable_help_flag = true)] to the Grep variant so clap does not intercept -h as --help before trailing_var_arg can collect it. Follows the pattern of merged PR rtk-ai#650 (psql disable_help_flag). Fixes rtk-ai#2391 Signed-off-by: axelray-dev <[email protected]>
axelray-dev
marked this pull request as ready for review
June 21, 2026 18:07
This was referenced Jun 25, 2026
5 tasks done
devnulled
added a commit
to devnulled/rtk
that referenced
this pull request
Aug 30, 2026
rtk's own tuning options on `Commands::Grep` declared short forms that
collide with native grep/rg flags of the same letter. This removes the two
that remain, and deletes one option outright.
`--max-len` loses `-l`. `-l` is grep's --files-with-matches, and the old
binding split behavior on whether the PATTERN parsed as a usize:
- Non-numeric: clap rejected it, run_fallback re-ran raw grep, and the
user got the right answer. Wasteful, not harmful.
- Numeric: clap ACCEPTED it, and the result was silently wrong.
# hit.txt contains "listen on port 8080 today"; miss.txt does not
$ rtk grep -l 8080 hit.txt miss.txt
before: (no output) exit=1 <- claims nothing matched
after: hit.txt exit=0
`-l 8080` set max_len=8080, leaving hit.txt as the pattern and miss.txt
as the only path. With a single file the filename becomes the pattern,
no path is left, and rtk falls back to stdin: exit 1 against /dev/null,
hangs on a terminal. Port numbers, years and error codes are ordinary
patterns, and the Claude Code hook rewrites plain `grep` into `rtk grep`
transparently -- so this reached users who never opted in.
Note this is not a savings story. `-l` is a has_format_flag passthrough
on the fixed path too (search.rs:548), so there is no compaction for
this flag either way. The bug was a wrong answer.
`--file-type` is removed entirely, with its `-t` short, rather than left as
a parse-only no-op. It was destructured as `file_type: _` at the call site
and never reached search::run, so it parsed and then did nothing.
`rtk rg -t rust` is unaffected: Rg has no such field and forwards `-t` to
real ripgrep.
Deliberately typed `fix`, not `fix!`, even though a documented long option
disappears. The option was inert -- it never filtered anything -- so no
working behavior is lost, and rtk-ai#3259 set the precedent for removing a
colliding grep short under plain `fix`. Recording the choice here because
silence would read as an oversight.
User-visible consequence: `rtk grep -t rust` goes from silently returning
unfiltered results to surfacing the engine's own error. BSD/macOS grep
prints `invalid option -- t`; GNU grep prints `invalid option -- 't'`.
`--max`/`-m` is NOT part of this change. rtk-ai#3259 removed that short already;
this branch is rebased onto it and preserves its rationale comment verbatim.
The struct NOTE deliberately does not claim to finish the job. clap's auto
`-h` still shadows grep/rg's --no-filename (that is rtk-ai#2532's scope), and
removing a clap short does not make a letter safe end to end: search.rs
shares one VALUE_FLAGS_SHORT table across both engines, so a letter taking
a value in rg but not grep still eats the next token inside a cluster --
`rtk grep -rt FOO .` consumes FOO as -t's value regardless of clap.
Adds clap-layer tests pinning the routing, including characterization tests
for behavior that was previously untested.
devnulled
added a commit
to devnulled/rtk
that referenced
this pull request
Aug 30, 2026
1. The --file-type removal had ZERO coverage. Restoring the option long-only
(no `-t`) left the entire suite green, so nothing stopped it creeping
back. Added test_grep_file_type_option_is_gone, which pins that the flag
routes to extra_args. Note it is NOT a clap error -- unknown long flags
fall through to the trailing slot -- so an is_err() assertion would be
wrong; grep is what rejects it. Mutation-proved:
# --file-type restored long-only (+ file_type: _ so it compiles)
assertion `left == right` failed
left: ["FOO", "src/"]
right: ["--file-type", "rust", "FOO", "src/"]
test result: FAILED. 0 passed; 1 failed
2. max_len_long_option_still_binds_to_rtk guarded on rg_available(), but
`rtk grep` execs grep, never rg (search.rs: `Engine::Grep => "grep"`).
On a box without ripgrep the test skipped and reported success, hiding
the mutant it exists to catch. Added grep_available() and switched to it.
Proved with the call site discarding max_len and rg off PATH:
$ PATH=/usr/bin:/bin search_compress_test max_len_long_option
--max-len must still bind after the short form was removed
(narrow=83, default=83)
test result: FAILED. 0 passed; 1 failed
Before this change that invocation printed `ok`.
3. test_grep_options_after_pattern_stay_in_extra_args claimed to
demonstrate a `trailing_var_arg` gotcha. Removing trailing_var_arg leaves
it green -- `allow_hyphen_values` is what produces the behavior. Comment
corrected so it is not read as a guard on trailing_var_arg.
Also drops test_grep_parse_max_count_m_forwarded: it duplicates the
pre-existing test_try_parse_grep_dash_m_is_max_count (src/main.rs:3012),
which dies to the same mutant and asserts strictly more (it also pins
`max == 200`).
Walks back the Grep NOTE block, which overclaimed. It said this "completes"
the shadowed-short cleanup. It does not:
- clap's auto `-h` still beats grep/rg's --no-filename before the first
positional, and after it reaches search.rs's help check and execs
unfiltered. That is rtk-ai#2532's scope, so the comment now says so rather
than inviting the next reader to add disable_help_flag here.
- removing a clap short does not make the letter safe end-to-end.
search.rs shares one VALUE_FLAGS_SHORT table across both engines, so a
letter taking a value in rg but not grep still eats the next token in a
cluster: `rtk grep -rt FOO .` consumes FOO as -t's value no matter what
clap does. Noted as a search.rs defect, not fixed here.
Separately, .claude/hooks/rtk-suggest.sh mapped both `rg` and `grep` to
`rtk grep`, swapping engines. With --file-type gone, its suggestion for
`rg -t rust FOO` became `rtk grep -t rust FOO`, which grep rejects. Now
maps rg -> `rtk rg` and grep -> `rtk grep`.
2 tasks done
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2391.
Add
#[command(disable_help_flag = true)]to theGrepvariant so clap does not intercept-has--helpbeforetrailing_var_argcan collect it.Follows the pattern of merged PR #650 (psql disable_help_flag).
Problem
rtk grep -h PATTERN FILEprints rtk's help text and exits 0 instead of forwarding-hto grep/rg. Clap's auto-generated help flag intercepts-hbefore the trailing var-arg collection runs.Fix
One-line addition to
src/main.rs:Side effect
rtk grep --helpforwards to rg/grep help instead of rtk's usage text. This matches the psql behavior.Tests
rtk grep -h alpha a.txt b.txtshows search matches, not help textrtk grep --helpforwards to underlying tool helprtk grep -v pattern .still workscargo testpassesComplementary to PR #2334 (rewrite-layer passthrough). Both fixes can coexist.
DCO: Signed-off.