-
Notifications
You must be signed in to change notification settings - Fork 70
add grep tool formatters #1019
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 07-02/pi-tool-formatter-edit
Are you sure you want to change the base?
add grep tool formatters #1019
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -123,6 +123,30 @@ def format_edit | |
| ok_line(@input[:path]) | ||
| end | ||
|
|
||
| # Formats a grep tool result. | ||
| # | ||
| # Content: matching lines, and possibly informational notes, one per | ||
| # line. | ||
| # | ||
| # Output: "GREP OK <n> <match|matches>[ · NOTE <notes>]" – <n> counts | ||
| # lines that look like matches (a leading path or line-number prefix); | ||
| # any remaining lines are joined into a truncated NOTE, shown only when | ||
| # there are both matches and notes. | ||
| # | ||
| # Examples: | ||
| # GREP OK 3 matches | ||
| # GREP OK 1 match | ||
| # GREP OK 0 matches | ||
| # | ||
| #: () -> String | ||
| def format_grep | ||
| lines = content.to_s.lines.map(&:strip).reject(&:empty?) | ||
| matches, notes = lines.partition { |line| line.match?(%r{\A\S+/}) || line.match?(/\A(?:\S+:)?\d+:/) } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Match/note heuristic is best-effort and will miscount. |
||
| count = matches.length | ||
| note = "NOTE #{truncate(notes.join(" "))}" if matches.any? && notes.any? | ||
| ok_line("#{count} #{"match".pluralize(count)}", note) | ||
| end | ||
|
|
||
| # Formats a result for which Roast has no dedicated formatter. | ||
| # | ||
| # Content: the tool's output text. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern is truncated but
path,glob, andlimitare appended untruncated, and they stack:GREP "<45>" <full path> (glob: <full glob>, limit: <n>)can easily run 150+ chars, contradicting the "generally one line" goal stated in the foundation comments. If the one-line bound matters, truncate the composed result; otherwise align the comment wording.