/** * Execute command on application container — goes through SDK. * * @module */ import { chalk, getCliSdk } from "../actions.js"; import { resolveUuid } from "../coolify-state.js"; import { resolveAppNameOrUuid } from "../name-resolver.js"; /** Execute a command on an application's running container. */ export async function execCommand( uuid: string | undefined, command: string, ): Promise { let resolved = resolveUuid(uuid); if (!resolved && uuid) { resolved = await resolveAppNameOrUuid(uuid); } if (!resolved) { console.error( chalk.red("Error: No UUID/name provided and no .coolify.json found"), ); return; } console.log(chalk.gray(`Executing on ${resolved}: ${command}`)); try { const result = await getCliSdk().applications.exec(resolved, command); if (result.response) { console.log(result.response); } else if (result.message) { console.log(chalk.green(result.message)); } } catch (error) { console.error( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } }