Comparing version 1.3.0 to 1.3.1
# node-dashdash changelog | ||
## 1.3.1 | ||
- [issue #1] Fix an envvar not winning over an option 'default'. Previously | ||
an option with both `default` and `env` would never take a value from the | ||
environment variable. E.g. `FOO_FILE` would never work here: | ||
options: [ { | ||
names: ['file', 'f'], | ||
env: 'FOO_FILE', | ||
'default': 'default.file', | ||
type: 'string' | ||
} ], | ||
## 1.3.0 | ||
@@ -4,0 +18,0 @@ |
@@ -291,11 +291,4 @@ /** | ||
var env = inputs.env || process.env; | ||
// Setup default values | ||
var opts = {}; | ||
var _order = []; | ||
this.options.forEach(function (o) { | ||
if (o.default) { | ||
opts[o.key] = o.default; | ||
} | ||
}); | ||
@@ -425,2 +418,10 @@ function addOpt(option, optstr, key, val, from) { | ||
// Apply default values. | ||
this.options.forEach(function (o) { | ||
if (o.default && opts[o.key] === undefined) { | ||
opts[o.key] = o.default; | ||
} | ||
}); | ||
opts._order = _order; | ||
@@ -427,0 +428,0 @@ opts._args = _args; |
{ | ||
"name": "dashdash", | ||
"description": "A light, featureful and explicit option parsing library.", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"author": "Trent Mick (trentm.com)", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -630,2 +630,36 @@ /* | ||
}, | ||
// issue #1: 'env' not taking precendence over 'default' | ||
{ | ||
options: [ { | ||
names: ['file', 'f'], | ||
env: 'FOO_FILE', | ||
'default': 'default.file', | ||
type: 'string' | ||
} ], | ||
argv: 'node foo.js', | ||
expect: { file: 'default.file', _args: [] } | ||
}, | ||
{ | ||
options: [ { | ||
names: ['file', 'f'], | ||
env: 'FOO_FILE', | ||
'default': 'default.file', | ||
type: 'string' | ||
} ], | ||
env: {FOO_FILE: 'env.file'}, | ||
argv: 'node foo.js', | ||
expect: { file: 'env.file', _args: [] } | ||
}, | ||
{ | ||
options: [ { | ||
names: ['file', 'f'], | ||
env: 'FOO_FILE', | ||
'default': 'default.file', | ||
type: 'string' | ||
} ], | ||
argv: 'node foo.js -f argv.file', | ||
env: {FOO_FILE: 'env.file'}, | ||
expect: { file: 'argv.file', _args: [] } | ||
}, | ||
]; | ||
@@ -632,0 +666,0 @@ cases.forEach(function (c, i) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105624
1342