|
| 1 | +import debug from 'debug'; |
| 2 | +import { devnetDeletePrompt } from '../../prompts/devnet.js'; |
| 3 | +import { globalOptions } from '../../utils/globalOptions.js'; |
| 4 | +import { |
| 5 | + getDevnetConfiguration, |
| 6 | + removeDevnetConfiguration, |
| 7 | +} from '../utils/devnetHelpers.js'; |
| 8 | + |
| 9 | +import chalk from 'chalk'; |
| 10 | +import { createExternalPrompt } from '../../prompts/generic.js'; |
| 11 | +import { createCommand } from '../../utils/createCommand.js'; |
| 12 | +import { |
| 13 | + dockerVolumeName, |
| 14 | + isDockerInstalled, |
| 15 | + removeDevnet, |
| 16 | + removeVolume, |
| 17 | +} from '../utils/docker.js'; |
| 18 | + |
| 19 | +export const deleteDevnetCommand = createCommand( |
| 20 | + 'delete', |
| 21 | + 'Delete devnet', |
| 22 | + [globalOptions.devnetSelect()], |
| 23 | + async (config) => { |
| 24 | + debug('devnet-delete:action')({ config }); |
| 25 | + |
| 26 | + const externalPrompt = createExternalPrompt({ |
| 27 | + devnetDeletePrompt, |
| 28 | + }); |
| 29 | + const deleteDevnet = await externalPrompt.devnetDeletePrompt(); |
| 30 | + |
| 31 | + if (deleteDevnet === 'no') { |
| 32 | + console.log( |
| 33 | + chalk.yellow( |
| 34 | + `\nThe devnet configuration "${config.name}" will not be deleted.\n`, |
| 35 | + ), |
| 36 | + ); |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + if (!isDockerInstalled()) { |
| 41 | + console.log( |
| 42 | + chalk.red( |
| 43 | + 'Stopping devnet requires Docker. Please install Docker and try again.', |
| 44 | + ), |
| 45 | + ); |
| 46 | + return; |
| 47 | + } |
| 48 | + |
| 49 | + removeDevnet(config.name); |
| 50 | + console.log(chalk.green(`Removed devnet container: ${config.name}`)); |
| 51 | + |
| 52 | + const configuration = getDevnetConfiguration(config.name); |
| 53 | + |
| 54 | + if (configuration?.useVolume) { |
| 55 | + removeVolume(config.name); |
| 56 | + console.log( |
| 57 | + chalk.green(`Removed volume: ${dockerVolumeName(config.name)}`), |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + console.log( |
| 62 | + chalk.green( |
| 63 | + `Successfully removed devnet container for configuration: ${config.name}`, |
| 64 | + ), |
| 65 | + ); |
| 66 | + |
| 67 | + removeDevnetConfiguration(config); |
| 68 | + |
| 69 | + console.log( |
| 70 | + chalk.green(`Successfully removed devnet configuration: ${config.name}`), |
| 71 | + ); |
| 72 | + }, |
| 73 | +); |
0 commit comments