fix(grep): return bare integer for -c/--count flag#1541
Open
CtriXin wants to merge 1 commit intortk-ai:masterfrom
Open
fix(grep): return bare integer for -c/--count flag#1541CtriXin wants to merge 1 commit intortk-ai:masterfrom
CtriXin wants to merge 1 commit intortk-ai:masterfrom
Conversation
`rtk grep -c pattern` now outputs just the count (matching `grep -c`), rather than the full grouped match listing. Fixes: rtk-ai#1452
|
|
Collaborator
📊 Automated PR Analysis
SummaryFixes the Review Checklist
Linked issues: #1452 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
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 -c <pattern> <file>now outputs just the bare integer count, matching plaingrep -csemantics.Root cause: the
-cflag was passed through torg(which outputsfile:countformat), but the code split on:expectingfile:linenum:content, misinterpreting the output. The full grouped match listing was returned instead of the count.Fix: detect
-c/--countinextra_args, route to dedicatedrun_count()path that sums all per-file counts fromrg -cand prints only the integer.Fixes: #1452
Test Plan
cargo test grep_cmd— 11 tests passrtk grep -c foo /tmp/filereturns single integercount=$(rtk grep -c pattern file)captures parseable integerNotes
-c) unchangedrgis used when available,grepas fallback (unchanged)