@ace-sdk/cli
Version:
ACE CLI - Command-line tool for intelligent pattern learning and playbook management
83 lines ⢠3.14 kB
JavaScript
/**
* Projects command - List all accessible projects across organizations
*
* Uses the new /api/v1/auth/projects endpoint (v4.5.8+) which works
* with user tokens directly - no org-level API tokens required.
*
* @package @ace-sdk/cli
* @since 3.8.0
*/
import chalk from 'chalk';
import { globalOptions } from '../cli.js';
import { Logger } from '../services/logger.js';
import { listProjects } from '@ace-sdk/core';
/**
* ce-ace projects list
* List all projects accessible to the current user
*/
export async function projectsListCommand(options = {}) {
const logger = new Logger(globalOptions);
const spinner = logger.spinner('Fetching projects...');
try {
const projects = await listProjects();
spinner?.succeed();
// Filter by org if specified
const filteredProjects = options.org
? projects.filter(p => p.org_id === options.org || p.org_name === options.org)
: projects;
if (logger.isJson()) {
logger.output({
projects: filteredProjects,
count: filteredProjects.length,
total: projects.length
});
return;
}
if (filteredProjects.length === 0) {
if (options.org) {
logger.info(chalk.dim(`No projects found in organization: ${options.org}`));
}
else {
logger.info(chalk.dim('No projects found.'));
logger.info(chalk.dim('Run `ce-ace login` to authenticate.'));
}
return;
}
// Group projects by organization
const byOrg = filteredProjects.reduce((acc, p) => {
const key = `${p.org_name} (${p.org_id})`;
acc[key] = acc[key] || [];
acc[key].push(p);
return acc;
}, {});
logger.info(chalk.bold(`\nš Your Projects (${filteredProjects.length}):\n`));
for (const [orgLabel, orgProjects] of Object.entries(byOrg)) {
logger.info(chalk.cyan.bold(orgLabel));
for (const project of orgProjects) {
logger.info(` ${chalk.green('ā')} ${chalk.bold(project.project_name)}`);
logger.info(chalk.dim(` ID: ${project.project_id}`));
logger.info(chalk.dim(` Created: ${new Date(project.created_at).toLocaleDateString()}`));
}
logger.info('');
}
if (!options.org && Object.keys(byOrg).length > 1) {
logger.info(chalk.dim('Tip: Use --org <org_id> to filter to a specific organization\n'));
}
}
catch (error) {
spinner?.fail();
if (logger.isJson()) {
logger.output({ error: error instanceof Error ? error.message : String(error) });
}
else {
logger.error('Failed to fetch projects', error instanceof Error ? error : String(error));
}
process.exit(1);
}
}
/**
* Legacy alias for backwards compatibility
* @deprecated Use projectsListCommand instead
*/
export const projectsCommand = projectsListCommand;
//# sourceMappingURL=projects.js.map