/** * Show command for CLI. * * Shows detailed information about an application. * * @module */ import { isErr } from "@mks2508/no-throw"; import chalk from "chalk"; import { getCoolifyService } from "../../coolify/index.js"; import { getCachedAppSettings } from "../../coolify/config.js"; import { resolveUuid } from "../coolify-state.js"; import { resolveAppNameOrUuid } from "../name-resolver.js"; /** * Show 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 showCommand(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 coolify = getCoolifyService(); const initResult = await coolify.init(); if (isErr(initResult)) { console.error(chalk.red(`Error: ${initResult.error.message}`)); return; } const result = await coolify.getApplication(uuid); if (isErr(result)) { console.error(chalk.red(`Error: ${result.error.message}`)); return; } const app = result.value; console.log(chalk.cyan("Application Details:")); console.log(""); console.log(chalk.gray("UUID: ") + chalk.white(app.uuid)); console.log(chalk.gray("Name: ") + chalk.white(app.name)); console.log(chalk.gray("Status: ") + chalk.white(app.status)); console.log( chalk.gray("Description:") + chalk.white(app.description || "N/A"), ); console.log( chalk.gray("Repository: ") + chalk.white(app.git_repository || "N/A"), ); console.log( chalk.gray("Branch: ") + chalk.white(app.git_branch || "N/A"), ); console.log( chalk.gray("Build Pack: ") + chalk.white(app.build_pack || "N/A"), ); console.log( chalk.gray("Ports: ") + chalk.white(app.ports_exposes || "N/A"), ); console.log(chalk.gray("FQDN: ") + chalk.white(app.fqdn || "N/A")); console.log( chalk.gray("Dockerfile: ") + chalk.white(app.dockerfile_location || "N/A"), ); console.log( chalk.gray("Base Dir: ") + chalk.white(app.base_directory || "N/A"), ); console.log(""); console.log(chalk.cyan("Deploy Settings:")); // Coolify API GET does not return settings.is_auto_deploy_enabled (stored in // application_settings table, not eager-loaded by the API). We check: // 1. API response (future-proof for when Coolify fixes this) // 2. Local cache (set when user runs `update --auto-deploy/--no-auto-deploy`) // 3. Default: ON (Coolify default) const cached = await getCachedAppSettings(uuid); const autoDeployFromApi = app.settings?.is_auto_deploy_enabled; const autoDeployFromCache = cached?.isAutoDeployEnabled; const autoDeployEnabled = autoDeployFromApi ?? autoDeployFromCache; if (autoDeployEnabled !== undefined) { const source = autoDeployFromApi ? "" : chalk.dim(" (cached)"); console.log( chalk.gray("Auto-deploy:") + (autoDeployEnabled ? chalk.green(" ON") : chalk.red(" OFF")) + source, ); } else { console.log( chalk.gray("Auto-deploy:") + chalk.dim(" unknown (default: ON, set via --auto-deploy/--no-auto-deploy)"), ); } if (app.watch_paths) { console.log(chalk.gray("Watch paths:")); for (const p of app.watch_paths.split("\n").filter(Boolean)) { console.log(chalk.gray(` ${p}`)); } } else { console.log( chalk.gray("Watch paths:") + chalk.yellow(" none (deploys on all changes)"), ); } console.log(""); console.log(chalk.cyan("Destination:")); if (app.destination) { console.log(chalk.gray(" UUID: ") + chalk.white(app.destination.uuid)); console.log(chalk.gray(" Name: ") + chalk.white(app.destination.name)); if (app.destination.server) { console.log( chalk.gray(" Server:") + chalk.white( ` ${app.destination.server.name} (${app.destination.server.ip})`, ), ); } } else { console.log(chalk.yellow(" No destination configured")); } console.log(""); console.log(chalk.cyan("Commands:")); if (app.install_command) console.log(chalk.gray(" Install: ") + chalk.white(app.install_command)); if (app.build_command) console.log(chalk.gray(" Build: ") + chalk.white(app.build_command)); if (app.start_command) console.log(chalk.gray(" Start: ") + chalk.white(app.start_command)); }