/** * Teams subcommands for CLI — all go through SDK. * * @module */ import { runList, chalk, getCliSdk } from "../actions.js"; import type { ICoolifyTeam } from "../../coolify/types.js"; /** List all teams. */ export const teamsListCommand = () => runList("team(s)", (s) => s.teams.list(), [ { header: "ID", value: (t) => String(t.id) }, { header: "Name", value: (t) => t.name }, { header: "Personal", value: (t) => (t.personal_team ? "Yes" : "No") }, ]); /** Get current team. */ export async function teamsCurrentCommand(): Promise { try { const team = await getCliSdk().teams.current(); console.log(chalk.cyan("Current Team:")); console.log(chalk.gray("ID: ") + team.id); console.log(chalk.gray("Name: ") + team.name); console.log(chalk.gray("Personal: ") + (team.personal_team ? "Yes" : "No")); } catch (error) { console.error( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } } /** Get team members. */ export async function teamsMembersCommand(teamId: string): Promise { const id = parseInt(teamId, 10); if (isNaN(id)) { console.error(chalk.red("Error: Team ID must be a number")); return; } try { const members = await getCliSdk().teams.members(id); if (members.length === 0) { console.log(chalk.yellow("No members found")); return; } console.log(chalk.cyan(`Team ${teamId} Members:`)); for (const m of members) { console.log(` ${chalk.bold(m.name)} (${chalk.gray(m.email)})`); } } catch (error) { console.error( chalk.red( `Error: ${error instanceof Error ? error.message : String(error)}`, ), ); } }