/** * Config command for CLI. * * @module */ import { isOk } from "@mks2508/no-throw"; import chalk from "chalk"; import { existsSync } from "node:fs"; import { loadConfig, saveConfig, CONFIG_FILE } from "../../coolify/config.js"; /** * Config command handler. * * @param action - Config action (set, get, path) * @param args - Action arguments */ export async function configCommand( action: string | undefined, args: { key?: string; value?: string }, ) { if (action === "set") { if (!args.key || !args.value) { console.error( chalk.red('Error: key and value are required for "set" command'), ); console.log(chalk.gray("Usage: coolify-mcp config set ")); console.log(chalk.gray("Keys: url, token")); return; } const result = await loadConfig(); if (isOk(result)) { const config = result.value; if (args.key === "url") { config.url = args.value; } else if (args.key === "token") { config.token = args.value; } else { console.error(chalk.red(`Error: Unknown key "${args.key}"`)); return; } const saveResult = await saveConfig(config); if (isOk(saveResult)) { console.log(chalk.green(`Config updated: ${args.key} = ${args.value}`)); } else { console.error(chalk.red(`Error: ${saveResult.error.message}`)); } } } else if (action === "get") { const result = await loadConfig(); if (isOk(result)) { const config = result.value; console.log(chalk.cyan("Current configuration:")); console.log(` URL: ${chalk.gray(config.url || "(not set)")}`); console.log( ` Token: ${chalk.gray(config.token ? "(set)" : "(not set)")}`, ); } else { console.error(chalk.red(`Error: ${result.error.message}`)); } } else if (action === "path") { console.log(chalk.cyan("Config file:")); console.log(` ${CONFIG_FILE}`); if (existsSync(CONFIG_FILE)) { console.log(chalk.gray(" Status: File exists")); } else { console.log(chalk.yellow(" Status: File does not exist")); } } else { console.log(chalk.cyan("Coolify MCP Configuration")); console.log(); console.log(chalk.gray("Commands:")); console.log(" coolify-mcp config set Set a config value"); console.log(" coolify-mcp config get Show current config"); console.log( " coolify-mcp config path Show config file path", ); console.log(); console.log(chalk.gray("Keys:")); console.log(" url - Coolify instance URL"); console.log(" token - Coolify API token"); console.log(); console.log(chalk.gray("Environment variables:")); console.log(" COOLIFY_URL - Coolify instance URL"); console.log(" COOLIFY_TOKEN - Coolify API token"); } }