import { Command } from 'commander'; import chalk from 'chalk'; import { getApiKey, setApiKey, getProjectId, setProjectId, getApiUrl, setApiUrl } from '../utils/config.js'; export function createConfigCommand() { const config = new Command('config'); config .description('View or modify Rigstate configuration') .argument('[key]', 'Configuration key to view/set (api_key, project_id, api_url)') .argument('[value]', 'Value to set') .action(async (key?: string, value?: string) => { // No arguments - show all config if (!key) { console.log(chalk.bold('Rigstate Configuration')); console.log(chalk.dim('─'.repeat(40))); try { const apiKey = getApiKey(); console.log(`${chalk.cyan('api_key')}: ${apiKey.substring(0, 20)}...`); } catch (e) { console.log(`${chalk.cyan('api_key')}: ${chalk.dim('(not set)')}`); } const projectId = getProjectId(); console.log(`${chalk.cyan('project_id')}: ${projectId || chalk.dim('(not set)')}`); const apiUrl = getApiUrl(); console.log(`${chalk.cyan('api_url')}: ${apiUrl}`); console.log(''); console.log(chalk.dim('Use "rigstate config " to set a value.')); return; } // Get specific key if (!value) { switch (key) { case 'api_key': try { const apiKey = getApiKey(); console.log(apiKey); } catch (e) { console.log(chalk.dim('(not set)')); } break; case 'project_id': console.log(getProjectId() || chalk.dim('(not set)')); break; case 'api_url': console.log(getApiUrl()); break; default: console.log(chalk.red(`Unknown config key: ${key}`)); console.log(chalk.dim('Valid keys: api_key, project_id, api_url')); } return; } // Set value switch (key) { case 'api_key': setApiKey(value); console.log(chalk.green(`✅ api_key updated`)); break; case 'project_id': setProjectId(value); console.log(chalk.green(`✅ project_id updated`)); break; case 'api_url': setApiUrl(value); console.log(chalk.green(`✅ api_url updated`)); break; default: console.log(chalk.red(`Unknown config key: ${key}`)); console.log(chalk.dim('Valid keys: api_key, project_id, api_url')); } }); return config; }