Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
patison
committed
Aug 14, 2012
1 parent
a73de66
commit 4f97f72
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var argOptions = {}, | ||
argParams = []; | ||
|
||
var rx = /^-?-(\w+)(?:=(.*))?$/; | ||
var argv = process.argv; | ||
|
||
argv.shift(); | ||
argv.shift(); | ||
|
||
argv.forEach(function(item) { | ||
if (matches = item.match(rx)) { | ||
var key = matches[1]; | ||
var val = matches[2] ? matches[2] : true; | ||
|
||
if (argOptions[key]!=undefined) { | ||
if( !(typeof argOptions[key] == "Array") ) | ||
argOptions[key] = [argOptions[key]]; | ||
|
||
argOptions[key].push(val); | ||
} | ||
else | ||
argOptions[key] = val; | ||
} | ||
else | ||
argParams.push(item); | ||
}); | ||
|
||
exports.opts = argOptions; | ||
exports.params = argParams; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name":"named-argv", | ||
"description":"a simple node module that helps passing named arguments", | ||
"keywords": [""], | ||
"version":"0.1.0", | ||
"repository": {"type": "git", "url": "git://github.com/ecdeveloper/node-named-argv"}, | ||
"author": "ecdeveloper <ec.developer@gmail.com>", | ||
"main":"./index.js" | ||
} |