MCPcopy
hub / github.com/coder/mux / parseSearchCommandArgs

Function parseSearchCommandArgs

src/node/services/tools/bash.ts:247–338  ·  view source on GitHub ↗
(
  command: SearchCommand,
  args: string[]
)

Source from the content-addressed store, hash-verified

245}
246
247function parseSearchCommandArgs(
248 command: SearchCommand,
249 args: string[]
250): { pattern: string | null; tokensAfterPattern: string[] } {
251 let pattern: string | null = null;
252 const tokensAfterPattern: string[] = [];
253 let afterDoubleDash = false;
254
255 const rgConsumesNextArg = new Set([
256 "-g",
257 "--glob",
258 "--iglob",
259 "-t",
260 "--type",
261 "--type-add",
262 "--type-clear",
263 ]);
264 const grepConsumesNextArg = new Set([
265 "-f",
266 "--file",
267 "--include",
268 "--exclude",
269 "--exclude-dir",
270 "-m",
271 "--max-count",
272 "-A",
273 "-B",
274 "-C",
275 ]);
276
277 for (let i = 0; i < args.length; i++) {
278 const token = args[i];
279
280 if (token === "--") {
281 afterDoubleDash = true;
282 continue;
283 }
284
285 if (pattern === null) {
286 const isFlag = !afterDoubleDash && token.startsWith("-");
287 if (isFlag) {
288 const patternFlagInline =
289 command === "rg" && token.startsWith("--regexp=")
290 ? token.slice("--regexp=".length)
291 : command === "grep" && token.startsWith("--regexp=")
292 ? token.slice("--regexp=".length)
293 : null;
294
295 if (patternFlagInline !== null) {
296 pattern = patternFlagInline;
297 continue;
298 }
299
300 const isExplicitPatternFlag =
301 (command === "rg" && (token === "-e" || token === "--regexp")) ||
302 (command === "grep" && token === "-e");
303
304 if (isExplicitPatternFlag) {

Callers 2

detectRipgrepFileDumpFunction · 0.85
detectGrepFileDumpFunction · 0.85

Calls 2

pushMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected