Skip to content

Commit

Permalink
Add support for --option=value syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Alhadis committed Dec 4, 2015
1 parent 36ba1ca commit d47b5c5
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function getOpts(input, optdef, config){
/** Optional options hash controlling option-creation */
config = config || {};
let noCamelCase = config.noCamelCase;
let ignoreEquals = config.ignoreEquals;


let shortNames = {};
Expand Down Expand Up @@ -170,6 +171,26 @@ function getOpts(input, optdef, config){
};


/** Is pre-processing of the argument list necessary? */
if(!ignoreEquals){

/** Limit equals-sign expansion to items that begin with recognised option names */
let legalNames = new RegExp("^(?:" + Object.keys(longNames).join("|") + ")=");

for(let i = 0, l = input.length; i < l; ++i){
let arg = input[i];

/** Expand "--option=value" sequences to become "--option value" */
if(legalNames.test(arg)){
let match = arg.match(/^([^=]+)=(.+)$/);
input.splice(i, 1, match[1], match[2]);
l = input.length;
i += 2;
continue;
}
}
}


/** Start processing the arguments we were given to handle */
for(let i = 0, l = input.length; i < l; ++i){
Expand Down

0 comments on commit d47b5c5

Please sign in to comment.