All files / src/cli cliRunner.ts

90.47% Statements 19/21
80% Branches 4/5
100% Functions 1/1
90.47% Lines 19/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36  1x 1x                 4x 4x   4x 4x 4x 4x 4x 4x 4x   4x 2x   4x       2x 2x   1x 1x 1x  
#!/usr/bin/env node
import { Command } from 'commander';
import { run } from '../index.js';
 
/**
 * Parses CLI arguments and runs the environment file generator.
 *
 * Expects `--map` and `--envfile` options to be provided, with an optional `--profile` for AWS CLI profile selection. Invokes the main process to generate a `.env` file from AWS SSM parameters based on the provided mapping.
 *
 * @throws {Error} If either `--map` or `--envfile` arguments are missing.
 */
export async function cliRunner() {
  const program = new Command();
 
  program
    .name('envilder')
    .description('A CLI tool to generate .env files from AWS SSM parameters')
    .version('0.1.0')
    .requiredOption('--map <path>', 'Path to the JSON file with environment variable mapping')
    .requiredOption('--envfile <path>', 'Path to the .env file to be generated')
    .option('--profile <name>', 'AWS CLI profile to use');
 
  await program.parseAsync(process.argv);
  const options = program.opts();
 
  if (!options.map || !options.envfile) {
    throw new Error('Missing required arguments: --map and --envfile');
  }
 
  await run(options.map, options.envfile, options.profile);
}
 
cliRunner().catch((error) => {
  console.error('🚨 Uh-oh! Looks like Mario fell into the wrong pipe! 🍄💥');
});