Repository navigation
fix(grep): stop -l/-m/-t shadowing native grep flags (adopt upstream #2628) - #91
Conversation
The Grep variant's own short options -l (max_len), -m (max) and -t (file_type) shadowed native grep/rg flags of the same letter. A leading `grep -l PATTERN` rewritten by the hook to `rtk grep -l PATTERN` made clap parse the pattern as a usize and abort (exit 2 -> raw fallback, zero token savings); -m and -t silently applied the wrong semantics. Make these tuning options long-only (--max-len/--max/--file-type) so the native flags route to extra_args and are parsed by grep_cmd.rs, which already handles them. Completes the -v/-n/pattern/path cleanup from 84616d1; complements the rg-only-flag handling tracked in rtk-ai#2224. Add clap-layer tests for the fix plus characterization tests for the previously-untested routing (combined -rn clusters, -v invert, -nE alternation, long-option binding, the trailing_var_arg ordering gotcha, --version passthrough and -- handling). Refs: rtk-ai#2614, rtk-ai#1604, rtk-ai#1436
…_cmd.rs The cherry-picked rtk-ai#2628 comments reference src/cmds/system/grep_cmd.rs, which upstream has since reworked into search.rs. Comment-only amendment; kept separate from the contributor's commit per adoption policy. Co-Authored-By: Claude Fable 5 <[email protected]>
Review round (pre-merge)Ran the two-axis /code-review (Standards + Spec, parallel sub-agents) against Standards: no hard violations. Noted: new tests use Spec: intent fully met — traced Quality gate re-run after the amendment: fmt clean, clippy zero warnings, 2599 unit tests + integration suites all green. |
Closes #52. Adopts upstream rtk-ai/rtk#2628 by @devnulled.
Commits
fix(grep): stop -l/-m/-t shadowing native grep flagsmain.rsis longer).No fork-authored amendments needed: the upstream commit already carries clap-layer characterization tests covering the fix and the surrounding routing.
What the bug actually is on current develop
The ticket said
rtk grep -l <pattern>hard-fails with exit 2. That's stale —run_fallbacknow rescues clap parse failures by executing raw grep. The live defect is worse: when the shadowed flag's value happens to parse, clap silently eats the flag and applies the wrong semantics with no error:-m 5(native max-count) binds to rtk's--max— flag never reaches grep-l 40binds40to--max-len—-l(files-with-matches) is dropped, output shows lines instead of filenames-t rustbinds to--file-type, which the handler ignores entirely (file_type: _in main.rs) — flag silently vanishesAnd when the value doesn't parse (
-l fn), the clap failure routes through the raw-exec fallback: output is correct but unfiltered, and a parse failure is recorded on every such call.Repro (debug binary, Git Bash on Windows)
Before (develop @ 62430db):
After (this branch):
-tnow forwards faithfully; native grep rejects it visibly (grep: unknown option -- t) instead of rtk silently discarding it. Type filtering remainsrtk rg -t.Blast radius checked
-l/-tonrtk grep(benchmark.sh:212,test-all.sh:262,test-aristote.sh:125) place the flag after the pattern, wheretrailing_var_argalready routed it toextra_args— behavior unchanged by this PR.search.rs-layer arg parsing or other flags; this PR is confined to the clap definitions and doesn't overlap. fix(grep): honor GNU -h/--no-filename instead of intercepting it as help rtk-ai/rtk#2635 (-h/--no-filename) is the natural next adoption.Quality gate
cargo fmt --all(no changes) &&cargo clippy --all-targets(zero warnings) &&cargo test --all— 2599 passed, 0 failed (x86_64 host toolchain, Windows).Deliberately not fixed
--file-typeremains parsed-but-ignored (file_type: _) — dead knob inherited from upstream; removing it is upstream's call, not adoption scope.search.rs-internal flag handling — covered by the sibling upstream PRs listed above.🤖 Generated with Claude Code