Skip to content

Commit 56a9285

Browse files
committed
Add grep docstring
1 parent a8ae9e7 commit 56a9285

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/eca/features/tools/filesystem.clj

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,18 @@
128128
(when (fs/exists? path)
129129
(flatten (search path))))))
130130

131-
(defn ^:private grep [arguments db]
131+
(defn ^:private grep
132+
"Searches for files containing patterns using regular expressions.
133+
134+
This function provides a fast content search across files using three different
135+
backends depending on what's available:
136+
1. ripgrep (rg) - fastest, preferred when available
137+
2. grep - standard Unix tool fallback
138+
3. Pure Java implementation - slow, but cross-platform fallback
139+
140+
Returns matching file paths, prioritizing by modification time when possible.
141+
Validates that the search path is within allowed workspace directories."
142+
[arguments db]
132143
(or (invalid-arguments arguments (concat (path-validations db)
133144
[["path" fs/readable? "File $path is not readable"]
134145
["pattern" #(and % (not (string/blank? %))) "Invalid content regex pattern '$pattern'"]
@@ -149,6 +160,7 @@
149160
:else
150161
(run-java-grep path pattern include))
151162
(take max-results))]
163+
;; TODO sort by modification time.
152164
(single-text-content (if (seq paths)
153165
(string/join "\n" paths)
154166
"No files found for given pattern")))))

0 commit comments

Comments
 (0)