* Checks if a command is available in the system's PATH. * @param {string} command The command name (e.g., 'git', 'grep'). * @returns {Promise } True if the command is available, false otherwise.
(command: string)
| 210 | * @returns {Promise<boolean>} True if the command is available, false otherwise. |
| 211 | */ |
| 212 | private isCommandAvailable(command: string): Promise<boolean> { |
| 213 | return new Promise((resolve) => { |
| 214 | const checkCommand = process.platform === 'win32' ? 'where' : 'command'; |
| 215 | const checkArgs = |
| 216 | process.platform === 'win32' ? [command] : ['-v', command]; |
| 217 | try { |
| 218 | const child = spawn(checkCommand, checkArgs, { |
| 219 | stdio: 'ignore', |
| 220 | shell: process.platform === 'win32', |
| 221 | }); |
| 222 | child.on('close', (code) => resolve(code === 0)); |
| 223 | child.on('error', () => resolve(false)); |
| 224 | } catch { |
| 225 | resolve(false); |
| 226 | } |
| 227 | }); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * Parses the standard output of grep-like commands (git grep, system grep). |