Created
January 16, 2016 03:01
-
-
Save jlamendo/51df5ae77856d4d55bc4 to your computer and use it in GitHub Desktop.
parseArgs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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