feat(cli): implement config display command
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { formatConfig } from './config-cmd.js';
|
||||
|
||||
describe('config command', () => {
|
||||
it('formats config as indented JSON with redacted secrets', () => {
|
||||
const config = {
|
||||
telegram: { bot_token: 'secret-123', allowed_chat_ids: [123] },
|
||||
models: { default: { provider: 'anthropic', model: 'claude', api_key: 'sk-abc' } },
|
||||
server: { port: 18800 },
|
||||
};
|
||||
|
||||
const output = formatConfig(config);
|
||||
expect(output).toContain('"bot_token": "***"');
|
||||
expect(output).toContain('"api_key": "***"');
|
||||
expect(output).toContain('"port": 18800');
|
||||
expect(output).not.toContain('secret-123');
|
||||
expect(output).not.toContain('sk-abc');
|
||||
});
|
||||
});
|
||||
+25
-3
@@ -1,12 +1,34 @@
|
||||
import type { Command } from 'commander';
|
||||
import { loadConfigSafe, getConfigPath, redactSecrets } from './shared.js';
|
||||
|
||||
/** Format config for display: redact secrets, return as JSON. */
|
||||
export function formatConfig(config: Record<string, unknown>): string {
|
||||
const redacted = redactSecrets(config);
|
||||
return JSON.stringify(redacted, null, 2);
|
||||
}
|
||||
|
||||
export function registerConfigCommand(program: Command): void {
|
||||
program
|
||||
.command('config')
|
||||
.description('Show resolved configuration (secrets redacted)')
|
||||
.option('-c, --config <path>', 'Config file path')
|
||||
.action(async (_opts: { config?: string }) => {
|
||||
console.error('Not yet implemented');
|
||||
process.exit(1);
|
||||
.option('--raw', 'Show unredacted config (dangerous)')
|
||||
.action(async (opts: { config?: string; raw?: boolean }) => {
|
||||
const configPath = opts.config ?? getConfigPath();
|
||||
const { config, error } = loadConfigSafe(configPath);
|
||||
|
||||
if (!config) {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Config loaded from: ${configPath}`);
|
||||
console.log('');
|
||||
|
||||
if (opts.raw) {
|
||||
console.log(JSON.stringify(config, null, 2));
|
||||
} else {
|
||||
console.log(formatConfig(config as unknown as Record<string, unknown>));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user