Skip to content

Commit

Permalink
Fixed bool options parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
whyleee committed Mar 14, 2014
1 parent b970a44 commit 2180137
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,14 @@ Command.prototype.parseOptions = function(argv){
, len = argv.length
, literal
, option
, arg;
, arg
, childOption;

var unknownOptions = [];

// parse options
for (var i = 0; i < len; ++i) {
childOption = false;
arg = argv[i];

// literal args after --
Expand All @@ -543,6 +545,24 @@ Command.prototype.parseOptions = function(argv){

// find matching Option
option = this.optionFor(arg);
if (!option) {
for (var command in this.commands) {
option = this.commands[command].optionFor(arg);
if (option) {
childOption = true;
break;
}
}
}

if (childOption) {
unknownOptions.push(arg);

if ((option.required || option.optional) && argv[i+1] && '-' != argv[i+1][0]) {
unknownOptions.push(argv[++i]);
}
continue;
}

// option is defined
if (option) {
Expand Down

0 comments on commit 2180137

Please sign in to comment.