UNPKG

@aerocorp/cli

Version:

AeroCorp CLI 5.1.0 - Future-Proofed Enterprise Infrastructure with Live Preview, Tunneling & Advanced DevOps

126 lines (104 loc) • 3.51 kB
import Conf from 'conf'; import chalk from 'chalk'; import { homedir } from 'os'; import { join } from 'path'; export class ConfigService { private config: Conf; constructor() { this.config = new Conf({ projectName: 'aerocorp-cli', configName: 'config', cwd: join(homedir(), '.aerocorp'), defaults: { coolify_url: 'https://coolify.aerocorpindustries.org', server_ip: '128.140.35.238', environment: 'production', authenticated: false, root_access: false } }); } async handleConfig(options: any) { if (options.set) { await this.setConfig(options.set); } else if (options.get) { await this.getConfig(options.get); } else if (options.list) { await this.listConfig(); } else if (options.reset) { await this.resetConfig(); } else { console.log(chalk.yellow('ℹ Config options:')); console.log(chalk.white(' --set <key=value> Set configuration value')); console.log(chalk.white(' --get <key> Get configuration value')); console.log(chalk.white(' --list List all configuration')); console.log(chalk.white(' --reset Reset configuration')); } } private async setConfig(keyValue: string) { const [key, ...valueParts] = keyValue.split('='); const value = valueParts.join('='); if (!key || !value) { throw new Error('Invalid format. Use: --set key=value'); } this.config.set(key, value); console.log(chalk.green(`āœ“ Set ${key} = ${value}`)); } private async getConfig(key: string) { const value = this.config.get(key); if (value !== undefined) { console.log(chalk.blue(`${key} = ${value}`)); } else { console.log(chalk.yellow(`⚠ Key '${key}' not found`)); } } private async listConfig() { console.log(chalk.cyan('šŸ“‹ AeroCorp CLI Configuration:')); console.log(chalk.cyan('================================')); const allConfig = this.config.store; // Mask sensitive values Object.entries(allConfig).forEach(([key, value]) => { let displayValue = value; if (key.includes('token') || key.includes('password')) { displayValue = typeof value === 'string' ? '*'.repeat(Math.min(value.length, 20)) : value; } const color = key.includes('token') ? 'red' : key.includes('url') ? 'blue' : key.includes('authenticated') ? 'green' : 'white'; console.log(chalk[color](` ${key}: ${displayValue}`)); }); // Show environment variables console.log(chalk.cyan('\nšŸŒ Environment Variables:')); const rootToken = process.env.AEROCORP_CLI_ROOT_API_TOKEN; if (rootToken) { console.log(chalk.red(` AEROCORP_CLI_ROOT_API_TOKEN: ${'*'.repeat(20)}`)); } else { console.log(chalk.gray(' AEROCORP_CLI_ROOT_API_TOKEN: (not set)')); } } private async resetConfig() { this.config.clear(); console.log(chalk.green('āœ“ Configuration reset successfully')); } get(key: string): any { return this.config.get(key); } set(key: string, value: any): void { this.config.set(key, value); } has(key: string): boolean { return this.config.has(key); } delete(key: string): void { this.config.delete(key); } clear(): void { this.config.clear(); } getAll(): Record<string, any> { return this.config.store; } getConfigPath(): string { return this.config.path; } }