Comparing version 1.8.0 to 1.9.0
# node-dashdash changelog | ||
## 1.9.0 | ||
- [issue #10] Custom option types added with `addOptionType` can specify a | ||
"default" value. See "examples/custom-option-fruit.js". | ||
## 1.8.0 | ||
@@ -4,0 +10,0 @@ |
@@ -515,4 +515,8 @@ /** | ||
this.options.forEach(function (o) { | ||
if (o.default !== undefined && opts[o.key] === undefined) { | ||
opts[o.key] = o.default; | ||
if (opts[o.key] === undefined) { | ||
if (o.default !== undefined) { | ||
opts[o.key] = o.default; | ||
} else if (optionTypes[o.type].default !== undefined) { | ||
opts[o.key] = optionTypes[o.type].default; | ||
} | ||
} | ||
@@ -748,2 +752,4 @@ }); | ||
* puts results in an array. | ||
* - default Optional. Default value for options of this type, if no | ||
* default is specified in the option type usage. | ||
*/ | ||
@@ -764,8 +770,8 @@ function addOptionType(optionType) { | ||
parseArg: optionType.parseArg, | ||
array: optionType.array | ||
array: optionType.array, | ||
default: optionType.default | ||
} | ||
} | ||
} | ||
module.exports = { | ||
@@ -772,0 +778,0 @@ createParser: createParser, |
{ | ||
"name": "dashdash", | ||
"description": "A light, featureful and explicit option parsing library.", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"author": "Trent Mick <trentm@gmail.com> (http://trentm.com)", | ||
@@ -6,0 +6,0 @@ "keywords": ["option", "parser", "parsing", "cli", "command", "args"], |
@@ -46,3 +46,18 @@ /* | ||
var fruits = [ | ||
'apple', | ||
'pear', | ||
'cherry', | ||
'strawberry', | ||
'banana' | ||
]; | ||
function parseFruit(option, optstr, arg) { | ||
if (fruits.indexOf(arg) === -1) { | ||
throw new Error(format('arg for "%s" is not a known fruit: "%s"', | ||
optstr, arg)); | ||
} | ||
return arg; | ||
} | ||
// ---- tests | ||
@@ -1010,2 +1025,38 @@ | ||
}, | ||
// optionType.default | ||
{ | ||
optionTypes: [ | ||
{ | ||
name: 'fruit', | ||
takesArg: true, | ||
helpArg: '<fruit>', | ||
parseArg: parseFruit, | ||
default: 'apple' | ||
} | ||
], | ||
options: [ {names: ['pie', 'p'], type: 'fruit'} ], | ||
argv: 'node foo.js', | ||
expect: { | ||
pie: 'apple', | ||
_args: [] | ||
} | ||
}, | ||
{ | ||
optionTypes: [ | ||
{ | ||
name: 'fruit', | ||
takesArg: true, | ||
helpArg: '<fruit>', | ||
parseArg: parseFruit, | ||
default: 'apple' | ||
} | ||
], | ||
options: [ {names: ['pie', 'p'], type: 'fruit'} ], | ||
argv: 'node foo.js -p pear', | ||
expect: { | ||
pie: 'pear', | ||
_args: [] | ||
} | ||
}, | ||
]; | ||
@@ -1012,0 +1063,0 @@ |
Sorry, the diff of this file is not supported yet
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
94176
19
2216