Skip to content

Instantly share code, notes, and snippets.

@jlamendo
Created January 16, 2016 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlamendo/51df5ae77856d4d55bc4 to your computer and use it in GitHub Desktop.
Save jlamendo/51df5ae77856d4d55bc4 to your computer and use it in GitHub Desktop.
parseArgs
function parseArgs(){
var opts_a=process.argv.slice(1,process.argv.length)
var opts={};
var prevArg=false;
opts_a.forEach(function(val,i){
var isFlag = ((val[0] === "-" && val[1] === "-" ) || ( val.length=2 && val[0] === "-"))
if(isFlag){
opts[val]="true";
prevArg=val;
} else if(prevArg !== false) {
opts[prevArg]=val;
prevArg = false;
}
});
return opts;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment