Repository navigation
fix(search): stop rtk grep from claiming the engine's short flags - #3664
dwin-gharibi wants to merge 1 commit into
Conversation
Commands::Grep declared -l (--max-len), -m (--max) and -t (--file-type), and no proxy subcommand except Psql disabled clap's automatic -h. Those letters belong to the proxied tool: -l is grep's --files-with-matches, -m its --max-count, -t rg's --type, and -h grep's --no-filename. When clap could parse the next token as the option's value it consumed both and the engine never saw the flag, so grep -l 404 a.log b.log searched b.log for the literal a.log and returned nothing, and grep -m 1 returned every match. When it could not, clap errored and run_fallback ran the raw command, which is why the bug looked intermittent. Drop the short forms, keep the long ones, and disable the help flag on Grep and Ls. -h stays a help request for rg, where it genuinely is one; for grep it now suppresses the filename prefix that rtk adds via its forced -H.
|
#3259 (merged 2026-08-29) dropped the -m short, #2628 (merged 2026-08-31) dropped -l and -t, and #3681 (merged 2026-09-12) moved search.rs onto the shared arg tokenizer, where -h already means no-filename for grep, so the search.rs hunks here target code that has been replaced. What develop still lacks is |
|
Thank you for this. The fix landed through #4348 (merged 2026-10-14), which stops rtk claiming -h on grep and ls, together with #3259 (2026-08-28) and #3681 (2026-09-12), which free -m, -l and -t for the engine and honour -h and --no-filename in the compressed output. The parse and display tests this PR adds are already covered by tests on develop, and the commands in your table now behave like native grep and ls. If a case is still missed, please comment or reopen. |
Closes #3663.
Summary
rtk grepno longer claims-l,-mor-t— those letters are grep's--files-with-matches, grep's--max-countand rg's--type. The knobs keep their longnames (
--max-len,--max,--file-type).disable_help_flagonGrepandLs, so clap stops claiming-h: it is--no-filenamefor grep and
--human-readablefor ls, not a help request. Follows the existingCommands::Psqlprecedent.-his still treated as help for rg (where it genuinely is), and for grep it nowsuppresses the filename prefix in the compressed output, since RTK forces
-Hon the enginefor its own parsing.
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk <command>output inspectedUnit tests (added, TDD — red before green)
src/main.rs:grep_does_not_swallow_engine_short_flags—-l,-m,-tall reachextra_args.Fails on
develop.dash_h_reaches_the_proxied_tool—rtk grep -h …andrtk ls -hparse instead oftriggering clap's help. Fails on
develop.grep_long_options_still_parse— control:--max-len 40 --max 5still bind rtk's ownfields. Passes before and after.
src/cmds/system/search.rs:no_filename_flag_suppresses_the_prefix—-h,--no-filenameand the-rhclustersuppress the filename prefix;
-Hstill forces it on. Fails ondevelop.Behavioural check against real grep / ls
grep -l 404 a.log b.loggrep -m 1 hit m.txtgrep -m 2 hit m.txtgrep -h 404 a.log b.loggrep -hn 404 a.log b.loggrep --no-filename 404 a.log b.logls -hControls confirming nothing else moved:
grep 404 a b(prefix still shown),grep -H 404 a,grep -n 404 a,grep -c 404 a b,grep -l GET a b,grep -m1 hit m.txt— all identicalbefore and after.
rtk grep --max-len 40 --max 5 404 a.logstill honours rtk's own options.Suite
cargo test --all: 2629 passed, 0 failed (2625 ondevelop, +4 from this PR).cargo clippy --all-targets: clean.cargo fmt --all: clean.