@ace-sdk/cli
Version:
ACE CLI - Command-line tool for intelligent pattern learning and playbook management
65 lines • 2.36 kB
JavaScript
/**
* Token Command - Display current API token
* @package @ace-sdk/cli
*/
import chalk from 'chalk';
import { getEffectiveToken, maskToken, getTokenType, isAuthenticated } from '@ace-sdk/core';
import { globalOptions } from '../cli.js';
export async function tokenCommand(options) {
// 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',
token: null,
token_type: null
}));
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 token = getEffectiveToken();
const tokenType = getTokenType();
if (!token) {
if (globalOptions.json) {
// Exit 0 in JSON mode - command succeeded, result is "no token"
console.log(JSON.stringify({
authenticated: true,
message: 'No token found',
token: null,
token_type: null
}));
return;
}
else {
console.log(chalk.red('No token found'));
process.exit(1);
}
}
const displayToken = options.reveal ? token : maskToken(token);
if (globalOptions.json) {
console.log(JSON.stringify({
token: options.reveal ? token : maskToken(token),
token_type: tokenType,
masked: !options.reveal
}));
}
else {
console.log();
console.log(chalk.cyan('API Token'));
console.log(chalk.gray('────────────────────────────────'));
console.log(chalk.gray('Type:'), chalk.white(tokenType === 'user' ? 'User Token' : 'Organization Token'));
console.log(chalk.gray('Token:'), chalk.white(displayToken));
if (!options.reveal) {
console.log();
console.log(chalk.gray('Use'), chalk.white('--reveal'), chalk.gray('to show full token'));
}
}
}
//# sourceMappingURL=token.js.map