Skip to content

fix(grep): return bare integer for -c/--count flag#1541

Open
CtriXin wants to merge 1 commit intortk-ai:masterfrom
CtriXin:fix/issue-1452-grep-count
Open

fix(grep): return bare integer for -c/--count flag#1541
CtriXin wants to merge 1 commit intortk-ai:masterfrom
CtriXin:fix/issue-1452-grep-count

Conversation

@CtriXin
Copy link
Copy Markdown

@CtriXin CtriXin commented Apr 26, 2026

Summary

rtk grep -c <pattern> <file> now outputs just the bare integer count, matching plain grep -c semantics.

Root cause: the -c flag was passed through to rg (which outputs file:count format), but the code split on : expecting file:linenum:content, misinterpreting the output. The full grouped match listing was returned instead of the count.

Fix: detect -c/--count in extra_args, route to dedicated run_count() path that sums all per-file counts from rg -c and prints only the integer.

Fixes: #1452

Test Plan

  • cargo test grep_cmd — 11 tests pass
  • Manual: rtk grep -c foo /tmp/file returns single integer
  • Manual: count=$(rtk grep -c pattern file) captures parseable integer

Notes

  • Existing grep output (without -c) unchanged
  • rg is used when available, grep as fallback (unchanged)

`rtk grep -c pattern` now outputs just the count (matching `grep -c`),
rather than the full grouped match listing.

Fixes: rtk-ai#1452
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Apr 26, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes the rtk grep -c flag to output a bare integer count instead of misinterpreting ripgrep's file:count format. A dedicated run_count() code path detects the -c/--count flag, sums per-file counts from rg -c output, and prints only the total integer, matching standard grep -c semantics.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1452


Analyzed automatically by wshm · This is an automated analysis, not a human review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(grep): -c count flag ignored — returns match summary + context instead of line count

4 participants