From 4635ff4947ad652cd054b5d9169a9c68b9e5f1c8 Mon Sep 17 00:00:00 2001 From: Nick Graef <1031317+ngraef@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:33:39 -0700 Subject: [PATCH] add --no-expand option to skip variable expansion --- cli.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli.js b/cli.js index 0372770..260ec89 100755 --- a/cli.js +++ b/cli.js @@ -9,7 +9,7 @@ var dotenvExpand = require('dotenv-expand').expand function printHelp () { console.log([ - 'Usage: dotenv [--help] [--debug] [-e ] [-v =] [-p ] [-c [environment]] [-- command]', + 'Usage: dotenv [--help] [--debug] [-e ] [-v =] [-p ] [-c [environment]] [--no-expand] [-- command]', ' --help print help', ' --debug output the files that would be processed but don\'t actually parse them or run the `command`', ' -e parses the file as a `.env` file and adds the variables to the environment', @@ -18,6 +18,7 @@ function printHelp () { ' -v = multiple -v flags are allowed', ' -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', ' 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')) } @@ -71,7 +72,10 @@ if (argv.debug) { } paths.forEach(function (env) { - dotenvExpand(dotenv.config({ path: path.resolve(env) })) + var parsedFile = dotenv.config({ path: path.resolve(env) }) + if (argv.expand !== false) { + dotenvExpand(parsedFile) + } }) Object.assign(process.env, parsedVariables)