/** * Databases command for CLI. * * Lists all databases in Coolify. * * @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"; /** * Databases command handler. * * @param options - Command options */ export async function databasesCommand(_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.listDatabases(); if (isErr(result)) { console.error(chalk.red(`Error: ${result.error.message}`)); return; } const databases = result.value; if (databases.length === 0) { console.log(chalk.yellow("No databases found")); return; } const table = new Table({ head: [ chalk.cyan("UUID"), chalk.cyan("Name"), chalk.cyan("Type"), chalk.cyan("Status"), ], }); for (const db of databases) { table.push([ db.uuid, db.name || "-", db.type || "-", formatStatus(db.status), ]); } console.log(table.toString()); console.log(chalk.gray(`Total: ${databases.length} database(s)`)); }