Skip to content

Commit

Permalink
Improve CLI option regex (#325)
Browse files Browse the repository at this point in the history
* ignore unsupported cli options ref #313

* test that dotenv_config_path via cli works ref #321
  • Loading branch information
maxbeatty committed Oct 2, 2018
1 parent 85ece25 commit 178e4ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion 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) {
Expand Down
10 changes: 9 additions & 1 deletion tests/test-cli-options.js
Expand Up @@ -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']), {})
5 changes: 3 additions & 2 deletions tests/test-config-cli.js
Expand Up @@ -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'
}
Expand Down

0 comments on commit 178e4ba

Please sign in to comment.