/** * Environments command for CLI. * * @module */ import { isOk, isErr } from "@mks2508/no-throw"; import ora from "ora"; import chalk from "chalk"; import Table from "cli-table3"; import { getCoolifyService } from "../../coolify/index.js"; /** * Environments command handler. * * @param projectUuid - Project UUID to get environments for * @param options - Command options */ export async function environmentsCommand( projectUuid: string, _options: { full?: boolean } = {}, ) { const spinner = ora("Connecting to Coolify...").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 = `Fetching environments for project ${projectUuid}...`; const result = await coolify.getProjectEnvironments(projectUuid); if (isOk(result)) { spinner.succeed(chalk.green("Environments retrieved")); const environments = result.value; if (environments.length === 0) { console.log(chalk.yellow("No environments found for this project")); return; } const table = new Table({ head: [ chalk.cyan("UUID"), chalk.cyan("Name"), chalk.cyan("Description"), ], }); for (const env of environments) { table.push([env.uuid, env.name, env.description || "-"]); } console.log(table.toString()); console.log(chalk.gray(`Total: ${environments.length} environment(s)`)); } else { spinner.fail( chalk.red(`Failed to fetch environments: ${result.error.message}`), ); } } catch (error) { spinner.fail( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } }