diff --git a/README.md b/README.md index 94c5a79..d2b2820 100644 --- a/README.md +++ b/README.md @@ -100,7 +100,7 @@ For more complex projects, a `.env-cmdrc` file can be defined in the root direct ``` ### --no-override option -Sometimes you want to set env variable which is set in a file without changing env file. +Sometimes you want to set env variables from a file without overriding existing process env vars. **Terminal** ```sh diff --git a/lib/index.js b/lib/index.js index 46740c9..3cd35ae 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,14 +11,14 @@ function EnvCmd (args) { const parsedArgs = ParseArgs(args) // If a .rc file was found then use that - let env = fs.existsSync(rcFileLocation) ? UseRCFile(parsedArgs) : UseCmdLine(parsedArgs) + let parsedEnv = fs.existsSync(rcFileLocation) ? UseRCFile(parsedArgs) : UseCmdLine(parsedArgs) // Add in the system environment variables to our environment list + let env = Object.assign({}, process.env, parsedEnv) + // Override the merge order if --no-override flag set if (parsedArgs.noOverride) { - env = Object.assign({}, env, process.env) - } else { - env = Object.assign({}, process.env, env) + env = Object.assign({}, parsedEnv, process.env) } // Execute the command with the given environment variables @@ -178,7 +178,7 @@ Also supports using a .env-cmdrc json file in the execution directory to support environment configs in one file. Options: - --no-override - if you do not wath shell envs to be overrided by env_file + --no-override - do not override existing process env vars with file env vars ` } diff --git a/package.json b/package.json index 0483a30..cbc6ab9 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "contributors": [ "Eric Lanehart ", "Jon Scheiding ", - "serapath (Alexander Praetorius) " + "serapath (Alexander Praetorius) ", + "Anton Versal " ], "license": "MIT", "bugs": {