commander
Advanced tools
Comparing version 0.1.0 to 0.2.0
0.2.0 / 2011-09-26 | ||
================== | ||
* Allow for defaults that are not just boolean. Default peassignment only occurs for --no-*, optional, and required arguments. [Jim Isaacs] | ||
0.1.0 / 2011-08-24 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -264,3 +264,4 @@ /*! | ||
, option = new Option(flags, description) | ||
, name = camelcase(option.name()); | ||
, oname = option.name() | ||
, name = camelcase(oname); | ||
@@ -270,8 +271,10 @@ // default as 3rd arg | ||
// when --no-* we default to true | ||
if (false == option.bool) defaultValue = true; | ||
// preassign default value only for --no-*, [optional], or <required> | ||
if (false == option.bool || option.optional || option.required) { | ||
// when --no-* we make sure default is true | ||
if (false == option.bool) defaultValue = true; | ||
// preassign only if we have a default | ||
if (undefined !== defaultValue) self[name] = defaultValue; | ||
} | ||
// default | ||
if (undefined !== defaultValue) self[name] = defaultValue; | ||
// register the option | ||
@@ -282,10 +285,17 @@ this.options.push(option); | ||
// and conditionally invoke the callback | ||
this.on(name, function(val){ | ||
this.on(oname, function(val){ | ||
// coercion | ||
if (null != val && fn) val = fn(val); | ||
// assign value | ||
self[name] = null == val | ||
? option.bool | ||
: val; | ||
// unassigned or bool | ||
if (/undefined|boolean/.test(typeof self[name])) { | ||
// if no value, bool true, and we have a default, then use it! | ||
self[name] = null == val | ||
? (option.bool | ||
? defaultValue || true : false | ||
) : val; | ||
} else { | ||
// reassign | ||
self[name] = val; | ||
} | ||
}); | ||
@@ -896,2 +906,2 @@ | ||
process.exit(0); | ||
}); | ||
}); |
{ | ||
"name": "commander" | ||
, "version": "0.1.0" | ||
, "version": "0.2.0" | ||
, "description": "the complete solution for node.js command-line programs" | ||
, "keywords": ["command", "option", "parser", "prompt", "stdin"] | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
, "repository": { "type": "git", "url": "https://github.com/visionmedia/commander.js.git" } | ||
, "dependencies": {} | ||
@@ -8,0 +9,0 @@ , "devDependencies": { "should": ">= 0.0.1" } |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
37729
29
946
0