From 907fcc6e90faacbd1a8665134b8004a1c5475d18 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Sat, 7 Jul 2018 08:11:15 -0700 Subject: [PATCH 1/2] ignore unsupported cli options ref #313 --- lib/cli-options.js | 2 +- tests/test-cli-options.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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']), {}) From bfb2269ec4e0ec3794b8b68678eaa586cbfdaff0 Mon Sep 17 00:00:00 2001 From: Max Beatty Date: Sat, 7 Jul 2018 08:11:54 -0700 Subject: [PATCH 2/2] test that dotenv_config_path via cli works ref #321 --- tests/test-config-cli.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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' }