fix(grep): accept -n flag for grep/rg compatibility#135
Merged
aeppling merged 2 commits intortk-ai:masterfrom Feb 20, 2026
Merged
fix(grep): accept -n flag for grep/rg compatibility#135aeppling merged 2 commits intortk-ai:masterfrom
aeppling merged 2 commits intortk-ai:masterfrom
Conversation
`rtk grep -n "pattern" path` failed with "unexpected argument '-n'" because clap didn't recognize -n before the positional arguments. Users naturally place -n before the pattern (muscle memory from grep/rg). The flag is a no-op since grep_cmd::run() already passes -n to ripgrep unconditionally, but clap must accept it. Adds -n/--line-numbers as an explicit bool field to the Grep command and ignores it in the match arm. Test added in grep_cmd::tests. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
54afe73 to
7d69299
Compare
Collaborator
|
Thanks for the fix — the approach is clean and correct. Same pattern as the The PR has merge conflicts with master (main.rs has changed a lot since Feb 15). Could you rebase on master and force-push? Once the conflicts are resolved, this is good to merge. |
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.
Summary
rtk grep -n "pattern" pathfails withunexpected argument '-n'because clap rejects unknown flags before positional arguments-nbefore the pattern (muscle memory fromgrep -n/rg -n)grep_cmd::run()already passes-nto ripgrep unconditionally (line 24) — but clap must accept itReproduction
Fix
Adds
-n/--line-numbersas an explicit bool field to theGrepcommand enum variant, ignored in the match arm (line_numbers: _). Same pattern asReadcommand which already defines-n(main.rs:105).Files Changed
src/main.rs-nflag to Grep, ignore in dispatch, add 2 clap parsing testsTest plan
cargo fmt --all --check— clean (no formatting changes in main.rs)cargo clippy --all-targets— 0 errorscargo test— 340 passedcargo run -- grep -n "fn run" src/grep_cmd.rs— works🤖 Generated with Claude Code