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

config: simplify regex #313

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function () {
require('./lib/main').config(
require('./lib/cli-options')(process.argv)
require('./lib/cli-options')(process.argv.slice(1)) // skip first argv, which is node command
)
})()
12 changes: 5 additions & 7 deletions lib/cli-options.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
const re = /^dotenv_config_(.+)=(.+)/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this PR could be simplified to:

-const re = /^dotenv_config_(.+)=(.+)/
+const re = /^dotenv_config_([^=]+)=(.+)$/

additional tests are always welcomed


module.exports = function optionMatcher (args) {
return args.reduce(function (acc, cur) {
const matches = cur.match(re)
module.exports = function (args) {
return args.reduce(function (options, val) {
var matches = val.match(/^dotenv_config_([^=]+)=(.+)$/)
if (matches) {
acc[matches[1]] = matches[2]
options[matches[1]] = matches[2]
}
return acc
return options
}, {})
}
Loading