(tokens: string[])
| 202 | } |
| 203 | |
| 204 | function parseSearch(tokens: string[]): ExploreEntry | null { |
| 205 | const commandName = tokens[0]?.toLowerCase() ?? ""; |
| 206 | const hasFilesFlag = tokens.some((token) => token === "--files"); |
| 207 | if (tokens[0] === "rg" && hasFilesFlag) { |
| 208 | const paths = findPathTokens(tokens); |
| 209 | const path = paths[paths.length - 1] || "rg --files"; |
| 210 | return { kind: "list", label: path }; |
| 211 | } |
| 212 | const positional = collectNonFlagOperands(tokens, commandName); |
| 213 | if (positional.length === 0) { |
| 214 | return null; |
| 215 | } |
| 216 | const query = positional[0]; |
| 217 | const rawPath = positional.length > 1 ? positional[1] : ""; |
| 218 | const path = |
| 219 | commandName === "rg" ? rawPath : rawPath && isPathLike(rawPath) ? rawPath : ""; |
| 220 | const label = path ? `${query} in ${path}` : query; |
| 221 | return { kind: "search", label }; |
| 222 | } |
| 223 | |
| 224 | function parseRead(tokens: string[]): ExploreEntry[] | null { |
| 225 | const paths = findPathTokens(tokens).filter(Boolean); |
no test coverage detected