@ace-sdk/cli
Version:
ACE CLI - Command-line tool for intelligent pattern learning and playbook management
73 lines • 2.82 kB
JavaScript
/**
* Orgs Command - List user's organizations
* @package @ace-sdk/cli
*/
import chalk from 'chalk';
import { getCurrentUser, isAuthenticated, getEffectiveOrgId } from '@ace-sdk/core';
import { globalOptions } from '../cli.js';
export async function orgsCommand() {
// Check if logged in
if (!isAuthenticated()) {
if (globalOptions.json) {
// Exit 0 in JSON mode - command succeeded, result is "not authenticated"
console.log(JSON.stringify({
authenticated: false,
message: 'Not logged in',
organizations: []
}));
return;
}
else {
console.log(chalk.yellow('Not logged in'));
console.log(chalk.gray('Run'), chalk.white('ace-cli login'), chalk.gray('to authenticate'));
process.exit(1);
}
}
const user = getCurrentUser();
const currentOrgId = getEffectiveOrgId();
if (!user) {
if (globalOptions.json) {
console.log(JSON.stringify({
warning: 'Using legacy token, no organization info available',
organizations: []
}));
}
else {
console.log(chalk.yellow('Using legacy token'));
console.log(chalk.gray('Organization info not available with legacy tokens'));
console.log(chalk.gray('Run'), chalk.white('ce-ace login'), chalk.gray('to upgrade to user authentication'));
}
return;
}
const orgs = user.organizations || [];
if (globalOptions.json) {
console.log(JSON.stringify({
count: orgs.length,
default_org_id: currentOrgId,
organizations: orgs
}));
}
else {
if (orgs.length === 0) {
console.log(chalk.yellow('No organizations found'));
console.log(chalk.gray('You may not be a member of any organizations'));
return;
}
console.log();
console.log(chalk.cyan(`Organizations (${orgs.length})`));
console.log(chalk.gray('────────────────────────────────────────'));
for (const org of orgs) {
const isDefault = currentOrgId === org.org_id;
if (isDefault) {
console.log(chalk.green('● ') + chalk.white(org.name) + chalk.green(' (default)'));
}
else {
console.log(chalk.gray('○ ') + chalk.white(org.name));
}
console.log(chalk.gray(` ID: ${org.org_id} Role: ${org.role}`));
}
console.log();
console.log(chalk.gray('Use'), chalk.white('ce-ace switch-org <name>'), chalk.gray('to change default'));
}
}
//# sourceMappingURL=orgs.js.map