From 78315a40c4efd077bf1c4b9dcee4316d118fbf4a Mon Sep 17 00:00:00 2001 From: Jeff Fairley Date: Fri, 17 Mar 2023 13:44:01 -0600 Subject: [PATCH] feat: expose 'override' option from 'dotenv' --- README.md | 8 ++++++++ cli.js | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e55269..00328a2 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,14 @@ Therefore, `dotenv-cli` will start a child process `bash -c 'echo "$SAY_HI"'` wi You can add the `--debug` flag to output the `.env` files that would be processed and exit. +### Override + +Override any environment variables that have already been set on your machine with values from your .env file. + +```bash +dotenv -c test -o -- jest +``` + ## License [MIT](https://en.wikipedia.org/wiki/MIT_License) diff --git a/cli.js b/cli.js index 260ec89..374ee72 100755 --- a/cli.js +++ b/cli.js @@ -19,6 +19,7 @@ function printHelp () { ' -p print value of to the console. If you specify this, you do not have to specify a `command`', ' -c [environment] support cascading env variables from `.env`, `.env.`, `.env.local`, `.env..local` files', ' --no-expand skip variable expansion', + ' -o, --override override system variables', ' command `command` is the actual command you want to run. Best practice is to precede this command with ` -- `. Everything after `--` is considered to be your command. So any flags will not be parsed by this tool but be passed to your command. If you do not do it, this tool will strip those flags' ].join('\n')) } @@ -72,7 +73,7 @@ if (argv.debug) { } paths.forEach(function (env) { - var parsedFile = dotenv.config({ path: path.resolve(env) }) + var parsedFile = dotenv.config({ path: path.resolve(env), override: argv.o || argv.override }) if (argv.expand !== false) { dotenvExpand(parsedFile) }