/** * Restart command for CLI. * * @module */ import { isErr } from "@mks2508/no-throw"; import ora from "ora"; import chalk from "chalk"; import { getCoolifyService } from "../../coolify/index.js"; import { resolveUuid } from "../coolify-state.js"; import { resolveAppNameOrUuid } from "../name-resolver.js"; /** * Restart command handler. * If no UUID is provided, reads from .coolify.json in the current directory. * * @param uuid - Application UUID (optional if .coolify.json exists) */ export async function restartCommand(uuid?: string) { 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 spinner = ora("Initializing Coolify connection...").start(); try { const coolify = getCoolifyService(); const initResult = await coolify.init(); if (isErr(initResult)) { spinner.fail( chalk.red(`Failed to initialize: ${initResult.error.message}`), ); return; } spinner.text = "Restarting application..."; const result = await coolify.restartApplication(uuid); if (isErr(result)) { spinner.fail( chalk.red(`Failed to restart application: ${result.error.message}`), ); return; } spinner.succeed(chalk.green(`Application restarted: ${chalk.cyan(uuid)}`)); } catch (error) { spinner.fail( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } }