|
| 1 | +import type { Command } from 'commander'; |
| 2 | +import type { CliContext } from '../../lib/types'; |
| 3 | +import { Console } from '../../lib/console'; |
| 4 | +import { handleError } from '../../lib/errors'; |
| 5 | +import { renderJson } from '../../lib/render'; |
| 6 | +import chalk from 'chalk'; |
| 7 | + |
| 8 | +export function registerInfoCommands(config: Command, ctx: CliContext) { |
| 9 | + config |
| 10 | + .command('env') |
| 11 | + .description('List whitelisted environment variables and their availability') |
| 12 | + .action(async () => { |
| 13 | + let spinner; |
| 14 | + if (ctx.config.output !== 'json') { |
| 15 | + spinner = Console.spinner('Fetching environment variables...'); |
| 16 | + } |
| 17 | + try { |
| 18 | + const response = await ctx.client.get('/api/v1/_config/environment-variables'); |
| 19 | + if (spinner) { |
| 20 | + spinner.succeed(chalk.green('✓ Environment variables retrieved')); |
| 21 | + } |
| 22 | + const data = response.data; |
| 23 | + |
| 24 | + if (ctx.config.output === 'json') { |
| 25 | + renderJson(data, ctx.config.jsonStyle); |
| 26 | + } else { |
| 27 | + Console.info(chalk.cyan('\n🔐 Environment Variables')); |
| 28 | + Console.info(chalk.gray('═'.repeat(60))); |
| 29 | + const vars = Array.isArray(data?.variables) ? data.variables : []; |
| 30 | + if (vars.length === 0) { |
| 31 | + Console.info(chalk.gray('No environment variables configured')); |
| 32 | + } else { |
| 33 | + vars.forEach((v: any) => { |
| 34 | + const status = v.available ? chalk.green('available') : chalk.yellow('not set'); |
| 35 | + Console.info(chalk.bold.blue(v.name) + ' ' + status); |
| 36 | + }); |
| 37 | + } |
| 38 | + } |
| 39 | + } catch (error) { |
| 40 | + if (spinner) { |
| 41 | + spinner.fail(chalk.red('✗ Failed to fetch environment variables')); |
| 42 | + } |
| 43 | + handleError(error, ctx.config); |
| 44 | + process.exitCode = 1; |
| 45 | + } |
| 46 | + }); |
| 47 | + |
| 48 | + config |
| 49 | + .command('filesystem') |
| 50 | + .description('Show the project filesystem structure') |
| 51 | + .action(async () => { |
| 52 | + let spinner; |
| 53 | + if (ctx.config.output !== 'json') { |
| 54 | + spinner = Console.spinner('Fetching filesystem structure...'); |
| 55 | + } |
| 56 | + try { |
| 57 | + const response = await ctx.client.get('/api/v1/_config/filesystem'); |
| 58 | + if (spinner) { |
| 59 | + spinner.succeed(chalk.green('✓ Filesystem structure retrieved')); |
| 60 | + } |
| 61 | + const data = response.data; |
| 62 | + |
| 63 | + if (ctx.config.output !== 'json') { |
| 64 | + Console.info(chalk.cyan('\n📁 Project Filesystem')); |
| 65 | + Console.info(chalk.gray('═'.repeat(60))); |
| 66 | + } |
| 67 | + renderJson(data, ctx.config.jsonStyle); |
| 68 | + } catch (error) { |
| 69 | + if (spinner) { |
| 70 | + spinner.fail(chalk.red('✗ Failed to fetch filesystem structure')); |
| 71 | + } |
| 72 | + handleError(error, ctx.config); |
| 73 | + process.exitCode = 1; |
| 74 | + } |
| 75 | + }); |
| 76 | +} |
0 commit comments