Comparing version 1.0.0 to 1.0.1
23
index.js
@@ -460,2 +460,3 @@ var MAX_LINE_WIDTH = process.stdout.columns || 200; | ||
this.values = {}; | ||
this.defaults_ = {}; | ||
@@ -485,2 +486,3 @@ this.suggestions = []; | ||
args_: noop, | ||
defaults_: null, | ||
@@ -529,3 +531,3 @@ option: function(usage, description, opt_1, opt_2){ | ||
}, | ||
setOption: function(name, value){ | ||
setOption: function(name, value, isDefault){ | ||
if (!this.hasOption(name)) | ||
@@ -540,2 +542,5 @@ throw new ParseError('Option `' + name + '` is not defined'); | ||
this.values[name] = option.maxArgsCount ? newValue : value; | ||
if (!hasOwnProperty.call(this.defaults_, name)) | ||
this.defaults_[name] = this.values[name]; | ||
}, | ||
@@ -547,3 +552,10 @@ setOptions: function(values){ | ||
}, | ||
reset: function(){ | ||
this.values = {}; | ||
for (var optionName in this.defaults_) | ||
if (hasOwnProperty.call(this.defaults_, optionName)) | ||
this.values[optionName] = this.defaults_[optionName]; | ||
}, | ||
command: function(nameOrCommand, params){ | ||
@@ -661,4 +673,2 @@ var name; | ||
//console.log(args); | ||
if (!errorHandler) | ||
@@ -673,3 +683,3 @@ return processArgs(this, args, suggest); | ||
}, | ||
run: function(args){ | ||
run: function(args, context){ | ||
var commands = this.parse(args); | ||
@@ -681,2 +691,3 @@ | ||
var prevCommand; | ||
var context = context || {}; | ||
for (var i = 0; i < commands.length; i++) | ||
@@ -687,2 +698,6 @@ { | ||
// reset command values | ||
command.reset(); | ||
command.context = context; | ||
if (prevCommand) | ||
@@ -689,0 +704,0 @@ prevCommand.delegate_(command); |
@@ -6,3 +6,3 @@ { | ||
"author": "Roman Dvornov <rdvornov@gmail.com>", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"keywords": ["cli", "command", "option", "argument", "completion"], | ||
@@ -9,0 +9,0 @@ "homepage": "https://github.com/lahmatiy/clap", |
21291
720