(command: string)
| 11 | * bodies and multi-line opaque tokens are never fed raw to shell-quote. |
| 12 | */ |
| 13 | export function extractPatternsFromCommand(command: string): string[] { |
| 14 | if (!command?.trim()) return [] |
| 15 | |
| 16 | const patterns = new Set<string>() |
| 17 | |
| 18 | // Split into sub-commands using the heredoc- and quote-aware parser so that |
| 19 | // constructs like heredocs or unterminated quotes are not broken up by |
| 20 | // shell-quote's operator splitting. |
| 21 | const { commands: subCommands } = parseCommand(command) |
| 22 | |
| 23 | for (const subCmd of subCommands) { |
| 24 | extractPatternsFromSingleCommand(subCmd, patterns) |
| 25 | } |
| 26 | |
| 27 | return Array.from(patterns).sort() |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Extract patterns from a single sub-command (no chaining operators) using |
no test coverage detected