/** * Server resources command for CLI. * * Shows resources deployed on a specific server. * * @module */ import { isErr } from "@mks2508/no-throw"; import chalk from "chalk"; import Table from "cli-table3"; import { getCoolifyService } from "../../coolify/index.js"; import { formatStatus } from "../../utils/format.js"; /** * Server resources command handler. * * @param serverUuid - Server UUID * @param options - Command options */ export async function serverResourcesCommand( serverUuid: string, _options: { full?: boolean } = {}, ) { const coolify = getCoolifyService(); const initResult = await coolify.init(); if (isErr(initResult)) { console.error(chalk.red(`Error: ${initResult.error.message}`)); return; } const result = await coolify.getServerResources(serverUuid); if (isErr(result)) { console.error(chalk.red(`Error: ${result.error.message}`)); return; } const resources = result.value; if (resources.length === 0) { console.log(chalk.yellow("No resources found on this server")); return; } const table = new Table({ head: [ chalk.cyan("UUID"), chalk.cyan("Name"), chalk.cyan("Type"), chalk.cyan("Status"), ], }); for (const res of resources) { table.push([ res.uuid, res.name || "-", res.type || "-", formatStatus(res.status), ]); } console.log(table.toString()); console.log( chalk.gray( `Total: ${resources.length} resource(s) on server ${serverUuid}`, ), ); }