( name: string, configManager: ConfigManager, registryClient: RegistryClient, forceUserLevel: boolean = false, forceProjectLevel: boolean = false )
| 188 | } |
| 189 | |
| 190 | async function addCommand( |
| 191 | name: string, |
| 192 | configManager: ConfigManager, |
| 193 | registryClient: RegistryClient, |
| 194 | forceUserLevel: boolean = false, |
| 195 | forceProjectLevel: boolean = false |
| 196 | ): Promise<void> { |
| 197 | const spinner = logger.spinner(`Fetching command: ${name}`) |
| 198 | |
| 199 | try { |
| 200 | const command = await registryClient.findCommand(name) |
| 201 | |
| 202 | if (!command) { |
| 203 | spinner.fail(`Command "${name}" not found`) |
| 204 | return |
| 205 | } |
| 206 | |
| 207 | spinner.text = `Downloading ${command.name}...` |
| 208 | |
| 209 | const content = await registryClient.fetchFileContent(command.file) |
| 210 | const commandsPath = await configManager.getCommandsPath() |
| 211 | const filePath = path.join(commandsPath, `${command.name}.md`) |
| 212 | |
| 213 | // Check if file already exists |
| 214 | const { fileExists } = await import('../utils/files.js') |
| 215 | if (await fileExists(filePath)) { |
| 216 | spinner.stop() |
| 217 | |
| 218 | const { action } = await inquirer.prompt([ |
| 219 | { |
| 220 | type: 'list', |
| 221 | name: 'action', |
| 222 | message: `Command "${command.name}" already exists. What would you like to do?`, |
| 223 | choices: [ |
| 224 | { name: 'Overwrite - Replace the existing file with the new one', value: 'overwrite' }, |
| 225 | { name: 'Skip - Skip this item and continue with other installations', value: 'skip' }, |
| 226 | { name: 'Abort - Stop the entire installation process', value: 'abort' } |
| 227 | ] |
| 228 | } |
| 229 | ]) |
| 230 | |
| 231 | if (action === 'skip') { |
| 232 | logger.info(`Skipped command: ${command.name}`) |
| 233 | return |
| 234 | } else if (action === 'abort') { |
| 235 | logger.info('Installation aborted') |
| 236 | process.exit(0) |
| 237 | } |
| 238 | |
| 239 | spinner.start(`Installing ${command.name}...`) |
| 240 | } |
| 241 | |
| 242 | await writeFile(filePath, content) |
| 243 | await configManager.addInstalledCommand(command.name) |
| 244 | |
| 245 | spinner.succeed(`Successfully installed command: ${command.prefix}${command.name}`) |
| 246 | logger.info(`Location: ${filePath}`) |
| 247 | } catch (error) { |
no test coverage detected