Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dashdash

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dashdash - npm Package Compare versions

Comparing version 1.8.0 to 1.9.0

examples/custom-option-fruit.js

6

CHANGES.md
# 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 @@

16

lib/dashdash.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc