|
| 1 | +import process from 'node:process' |
1 | 2 | import { CAC } from 'cac' |
2 | 3 | import { version } from '../package.json' |
3 | | -import { defaultConfigDir, defaultGeneratedDir, generateConfigTypes } from '../src/config' |
| 4 | +import { config, defaultConfigDir, defaultGeneratedDir, generateConfigTypes } from '../src/config' |
4 | 5 |
|
5 | 6 | const cli = new CAC('bunfig') |
6 | 7 |
|
7 | 8 | // Define CLI options interface to match our core types |
8 | 9 | interface CLIOptions { |
9 | 10 | configDir?: string |
10 | 11 | generatedDir?: string |
| 12 | + verbose?: boolean |
11 | 13 | } |
12 | 14 |
|
13 | 15 | cli |
|
17 | 19 | .option('--verbose', 'Enable verbose logging') |
18 | 20 | .example('bunfig generate --config-dir ./config --generated-dir ./src/generated') |
19 | 21 | .action(async (options?: CLIOptions) => { |
20 | | - console.log('Generating config types...') |
21 | 22 | generateConfigTypes({ |
22 | 23 | configDir: options?.configDir || defaultConfigDir, |
23 | 24 | generatedDir: options?.generatedDir || defaultGeneratedDir, |
24 | 25 | }) |
25 | 26 | }) |
26 | 27 |
|
27 | | -cli.command('', 'Show the version of the Bunfig CLI').action(() => { |
28 | | - console.log(version) |
29 | | -}) |
| 28 | +cli |
| 29 | + .command('show <name>', 'Show the loaded configuration for the specified name') |
| 30 | + .option('--verbose', 'Enable verbose logging') |
| 31 | + .example('bunfig show my-app') |
| 32 | + .action(async (name: string, options?: { verbose?: boolean }) => { |
| 33 | + try { |
| 34 | + const loadedConfig = await config({ |
| 35 | + name, |
| 36 | + defaultConfig: {}, |
| 37 | + verbose: options?.verbose, |
| 38 | + }) |
| 39 | + console.log(JSON.stringify(loadedConfig, null, 2)) |
| 40 | + } |
| 41 | + catch (error) { |
| 42 | + console.error('Failed to load configuration:', error) |
| 43 | + process.exit(1) |
| 44 | + } |
| 45 | + }) |
30 | 46 |
|
31 | 47 | cli.command('version', 'Show the version of the Bunfig CLI').action(() => { |
32 | 48 | console.log(version) |
|
0 commit comments