lambda-live-debugger
Version:
Debug Lambda functions locally like it is running in the cloud
58 lines (57 loc) • 3.06 kB
JavaScript
import { Command, InvalidOptionArgumentError } from 'commander';
import { getVersion } from '../version.mjs';
import { defaultObservableInterval, outputFolder } from '../constants.mjs';
const validRemoveOptions = ['keep-layer', 'all'];
/**
* Get configuration from CLI arguments
* @param supportedFrameworks Supported frameworks
* @returns Configuration
*/
export async function getConfigFromCliArgs(supportedFrameworks = []) {
const version = await getVersion();
const program = new Command();
program.name('lld').description('Lambda Live Debugger').version(version);
program.option('-r, --remove [option]', "Remove Lambda Live Debugger infrastructure. Options: 'keep-layer' (default), 'all'. The latest also removes the Lambda Layer");
program.option('-w, --wizard', 'Program interactively asks for each parameter and saves it to lldebugger.config.ts');
program.option('-v, --verbose', 'Verbose logging');
program.option('-c, --context <context>', 'AWS CDK context', (value, previous) => previous.concat(value), []);
program.option('-s, --stage <stage>', 'Serverless Framework stage');
program.option('-f, --function <function name>', 'Filter by function name. You can use * as a wildcard');
program.option('-m, --subfolder <subfolder>', 'Monorepo subfolder');
program.option('-o, --observable', 'Observability mode');
program.option('-i --interval <interval>', 'Observability mode interval', defaultObservableInterval.toString());
program.option('-a, --approval', 'User approval required for AWS infrastructure changes, like adding a Lambda layer');
program.option('--config-env <evironment>', 'SAM environment');
program.option('--sam-config-file <file>', 'SAM configuration file');
program.option('--sam-template-file <file>', 'SAM template file');
program.option('--sam-stack-name <name>', 'SAM stack name');
program.option('--profile <profile>', 'AWS profile to use');
program.option('--region <region>', 'AWS region to use');
program.option('--role <role>', 'AWS role to use');
program.option('--framework <framework>', `Framework to use (${supportedFrameworks.join(', ')})`);
program.option('--gitignore', `Add ${outputFolder} to .gitignore`);
program.parse(process.argv);
const args = program.opts();
args.interval = parseInt(args.interval);
if (args.remove === true) {
args.remove = 'keep-layer';
}
else if (args.remove) {
if (!validRemoveOptions.includes(args.remove)) {
throw new InvalidOptionArgumentError(`Invalid option: '${args.remove}'. Valid options are: ${validRemoveOptions.join(', ')}`);
}
}
return args;
}
// function validateRemoveOption(value: any) {
// console.log("REMOVE", value);
// if (value === true) {
// return "keep-layer";
// }
// if (!validRemoveOptions.includes(value)) {
// throw new InvalidOptionArgumentError(
// `Invalid option: '${value}'. Valid options are: ${validRemoveOptions.join(", ")}`
// );
// }
// return value;
// }