diff --git a/lib/cli-options.js b/lib/cli-options.js index 1bfaa30c..36ecdf61 100644 --- a/lib/cli-options.js +++ b/lib/cli-options.js @@ -1,4 +1,4 @@ -const re = /^dotenv_config_(.+)=(.+)/ +const re = /^dotenv_config_(encoding|path)=(.+)$/ module.exports = function optionMatcher (args) { return args.reduce(function (acc, cur) { diff --git a/tests/test-cli-options.js b/tests/test-cli-options.js index 9c0b858c..d9fdb748 100644 --- a/tests/test-cli-options.js +++ b/tests/test-cli-options.js @@ -2,12 +2,20 @@ const t = require('tap') const options = require('../lib/cli-options') -t.plan(2) +t.plan(4) +// matches encoding option t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_encoding=utf8']), { encoding: 'utf8' }) +// matches path option t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_path=/custom/path/to/your/env/vars']), { path: '/custom/path/to/your/env/vars' }) + +// ignores empty values +t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_path=']), {}) + +// ignores unsupported options +t.same(options(['node', '-e', "'console.log(testing)'", 'dotenv_config_foo=bar']), {}) diff --git a/tests/test-config-cli.js b/tests/test-config-cli.js index 7c11efb8..548bef26 100644 --- a/tests/test-config-cli.js +++ b/tests/test-config-cli.js @@ -15,10 +15,11 @@ test('config preload loads .env', t => { '../config', '-e', 'console.log(process.env.BASIC)', - 'dotenv_config_encoding=utf8' + 'dotenv_config_encoding=utf8', + 'dotenv_config_path=./tests/.env' ], { - cwd: path.resolve(__dirname), + cwd: path.resolve(__dirname, '..'), timeout: 5000, encoding: 'utf8' }