From 00786d55087a6f081c917a60d12791e23aa79fa9 Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Fri, 8 Aug 2025 20:22:10 +0200 Subject: [PATCH] chore: minor QoL improvements --- README.md | 2 +- src/start.ts | 75 ++++++++++++++++++++++-------------------------- src/utils/cli.ts | 14 --------- 3 files changed, 35 insertions(+), 56 deletions(-) delete mode 100644 src/utils/cli.ts diff --git a/README.md b/README.md index 9b011d9..3ce7d44 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,7 @@ override the SSM-resolved values. To avoid this: - Use `.env.with-ssm` instead of `.env` for SSM references - Or use environment variable substitution if your app supports it: - `${API_KEY:-SSM:/myapp/api-key}` + `API_KEY=${API_KEY:-SSM:/myapp/api-key}` ### 🚀 Deployment Considerations diff --git a/src/start.ts b/src/start.ts index f436e9f..33d184a 100644 --- a/src/start.ts +++ b/src/start.ts @@ -5,48 +5,41 @@ import { exec } from './utils/exec.js'; import { getEnv } from './utils/env.js'; import { replaceParams } from './utils/ssm.js'; -const main = async () => { - const argv = await yargs(hideBin(process.argv)) - .usage('Usage: $0 [options] -- ') - .option('region', { - type: 'string', - description: 'The AWS region to use for SSM.', - }) - .option('profile', { - type: 'string', - description: 'The AWS profile to use from your credentials file.', - }) - .option('file', { - alias: 'f', - type: 'string', - description: 'The file to use for environment variables. (multiple files can be specified)', - default: ['.env', '.env.with-ssm'], - }) - .demandCommand(1, 'Error: You must provide a command to execute after --') - .alias('h', 'help') - .epilogue('For more information, check the documentation.') - .parse(); +const argv = await yargs(hideBin(process.argv)) + .usage('Usage: $0 [options] -- ') + .option('region', { + type: 'string', + description: 'The AWS region to use for SSM.', + }) + .option('profile', { + type: 'string', + description: 'The AWS profile to use from your credentials file.', + }) + .option('file', { + alias: 'f', + type: 'string', + description: 'The file to use for environment variables. (multiple files can be specified)', + default: ['.env', '.env.with-ssm'], + }) + .demandCommand(1, 'Error: You must provide a command to execute after --') + .alias('h', 'help') + .epilogue('For more information, check the documentation.') + .parse(); - const command = argv._[0] as string; - const commandArgs = argv._.slice(1).map(String); +const command = argv._[0] as string; +const commandArgs = argv._.slice(1).map(String); - if (!command) { - console.error('No command provided'); - process.exit(1); - } - - const files = argv.file && Array.isArray(argv.file) ? argv.file : [argv.file]; - const hostEnv = await getEnv(files); - const env = await replaceParams(hostEnv); - - exec({ - command, - env, - args: commandArgs, - }); -}; - -main().catch((err) => { - console.error(err); +if (!command) { + console.error('No command provided'); process.exit(1); +} + +const files = argv.file && Array.isArray(argv.file) ? argv.file : [argv.file]; +const hostEnv = await getEnv(files); +const env = await replaceParams(hostEnv); + +exec({ + command, + env, + args: commandArgs, }); diff --git a/src/utils/cli.ts b/src/utils/cli.ts deleted file mode 100644 index 4aa5cc4..0000000 --- a/src/utils/cli.ts +++ /dev/null @@ -1,14 +0,0 @@ -const splitArgs = (args: string[]) => { - const separatorIndex = args.indexOf('--'); - const actionArgs = args.slice(0, separatorIndex); - const command = args[separatorIndex + 1]; - const commandArgs = args.slice(separatorIndex + 2); - - return { - actionArgs, - command, - commandArgs, - }; -}; - -export { splitArgs };