/** * Delete application command. * * Deletes an existing Coolify application. * * @module */ import { isErr } from "@mks2508/no-throw"; import chalk from "chalk"; import { getCoolifyService } from "../../coolify/index.js"; import { resolveUuid } from "../coolify-state.js"; import { resolveAppNameOrUuid } from "../name-resolver.js"; /** * Executes the delete command. * If no UUID is provided, reads from .coolify.json in the current directory. * * @param uuid - Application UUID (optional if .coolify.json exists) * @param options - Command options */ export async function deleteCommand( uuid: string | undefined, options: { force?: boolean; yes?: boolean } = {}, ): Promise { let resolvedUuid = resolveUuid(uuid); if (!resolvedUuid && uuid) { resolvedUuid = await resolveAppNameOrUuid(uuid); } if (!resolvedUuid) { console.error( chalk.red("Error: No UUID/name provided and no .coolify.json found"), ); return; } uuid = resolvedUuid; const service = getCoolifyService(); const initResult = await service.init(); if (isErr(initResult)) { console.error(chalk.red("Failed to initialize Coolify service")); console.error(chalk.gray(initResult.error.message)); process.exit(1); } if (!options.force && !options.yes) { const readline = await import("readline"); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const answer = await new Promise((resolve) => { rl.question( chalk.yellow( `Are you sure you want to delete application ${chalk.bold(uuid)}? (yes/no): `, ), (ans) => { rl.close(); resolve(ans.toLowerCase()); }, ); }); if (answer !== "yes" && answer !== "y") { console.log(chalk.gray("Operation cancelled")); process.exit(0); } } console.log(chalk.cyan(`Deleting application ${chalk.bold(uuid)}...`)); const result = await service.deleteApplication(uuid); if (isErr(result)) { console.error(chalk.red("Failed to delete application")); console.error(chalk.gray(result.error.message)); process.exit(1); } console.log(chalk.green("Application deleted successfully")); if (result.value.message) { console.log(chalk.gray(result.value.message)); } }