Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: throw error when cascade and override are used together #93

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function printHelp () {
' -p <variable> print value of <variable> to the console. If you specify this, you do not have to specify a `command`',
' -c [environment] support cascading env variables from `.env`, `.env.<environment>`, `.env.local`, `.env.<environment>.local` files',
' --no-expand skip variable expansion',
' -o, --override override system variables',
' -o, --override override system variables. Cannot be used along with cascade (-c).',
' 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'))
}
Expand All @@ -29,6 +29,13 @@ if (argv.help) {
process.exit()
}

const override = argv.o || argv.override;

if (argv.c && override) {
console.error('Invalid arguments. Cascading env variables conflicts with overrides.')
process.exit(1)
}

var paths = []
if (argv.e) {
if (typeof argv.e === 'string') {
Expand Down Expand Up @@ -73,7 +80,6 @@ if (argv.debug) {
}

paths.forEach(function (env) {
const override = argv.o || argv.override;
var parsedFile = dotenv.config({ path: path.resolve(env), override })
if (argv.expand !== false) {
dotenvExpand(parsedFile)
Expand Down