Comparing version 0.0.4 to 0.1.6
42
index.js
var args | ||
options = {}, | ||
options = {}, | ||
required = {}, | ||
@@ -42,12 +42,25 @@ | ||
var result = {}, | ||
nameHash = {}, | ||
keys = {}, | ||
set = function(name, value){ | ||
var names = SET.call(result, name, value) | ||
set = SET.bind(result) | ||
names.forEach(function(name){ | ||
keys[name] = true | ||
//now set all default values | ||
var k, | ||
opt | ||
for (k in options) { | ||
opt = options[k] | ||
if (typeof opt != 'string' && opt.defaultValue != null){ | ||
set(k, opt.defaultValue) | ||
opt.aliases && opt.aliases.forEach(function(alias){ | ||
set(alias, opt.defaultValue) | ||
}) | ||
} | ||
} | ||
result = Object.create(result) | ||
var nameHash = {} | ||
set = SET.bind(result) | ||
values.forEach(function(arg){ | ||
@@ -72,17 +85,2 @@ var name = arg.name, | ||
//now set all default values | ||
var k, | ||
opt | ||
for (k in options) if (!keys[k]){ | ||
opt = options[k] | ||
if (typeof opt != 'string' && opt.defaultValue != null){ | ||
set(k, opt.defaultValue) | ||
opt.aliases && opt.aliases.forEach(function(alias){ | ||
set(alias, opt.defaultValue) | ||
}) | ||
} | ||
} | ||
return result | ||
@@ -89,0 +87,0 @@ } |
{ | ||
"name": "arguably", | ||
"version": "0.0.4", | ||
"version": "0.1.6", | ||
"description": "Command line arguments parser", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -9,3 +9,18 @@ arguably | ||
Let's say you have a script args.js, and call it with | ||
``` | ||
node args.js -u google.com --name bob | ||
``` | ||
or | ||
``` | ||
node args.js --url yahoo.com --name bill | ||
``` | ||
And want to simply print the given url and name. Your script should use arguably like this: | ||
``` | ||
var arguably = require('arguably'), | ||
@@ -22,3 +37,16 @@ args = arguably | ||
console.log(args.name) | ||
args.name === args.n | ||
console.log(args.url) | ||
args.url === args.u | ||
``` | ||
Notice that the **args** variable returned by arguably is an object with key/value pairs, as specified in the | ||
option description. On options with multiple aliases. like the url (-u or --url), the args has the save value | ||
for both of the aliases | ||
``` | ||
args.u === args.url | ||
``` |
var parser = require('./index'), | ||
args = parser | ||
.option('-h, --help') | ||
.option('-x, --xx', 'xx ','default') | ||
.done() | ||
console.log(args.x) | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7103
50
6
175