Comparing version 3.2.1 to 3.3.1
31
index.js
@@ -24,4 +24,4 @@ var path = require('path'); | ||
var self = {}; | ||
var usage = Usage(self); | ||
var validation = Validation(self, usage); | ||
var usage = null; | ||
var validation = null; | ||
@@ -47,3 +47,6 @@ if (!cwd) cwd = process.cwd(); | ||
var options; | ||
self.resetOptions = function () { | ||
self.resetOptions = self.reset = function () { | ||
// put yargs back into its initial | ||
// state, this is useful for creating a | ||
// nested CLI. | ||
options = { | ||
@@ -53,2 +56,3 @@ array: [], | ||
string: [], | ||
key: {}, | ||
alias: {}, | ||
@@ -62,2 +66,12 @@ default: {}, | ||
}; | ||
usage = Usage(self); // handle usage output. | ||
validation = Validation(self, usage); // handle arg validation. | ||
demanded = {}; | ||
exitProcess = true; | ||
helpOpt = null; | ||
versionOpt = null; | ||
return self; | ||
@@ -215,5 +229,8 @@ }; | ||
else { | ||
options.key[key] = true; // track manually set keys. | ||
if (opt.alias) self.alias(key, opt.alias); | ||
var demand = opt.demand || opt.required || opt.require; | ||
if (demand) { | ||
@@ -313,2 +330,10 @@ self.demand(key, demand); | ||
self.getUsageInstance = function () { | ||
return usage; | ||
}; | ||
self.getValidationInstance = function () { | ||
return validation; | ||
} | ||
Object.defineProperty(self, 'argv', { | ||
@@ -315,0 +340,0 @@ get : function () { |
@@ -43,22 +43,7 @@ // fancy-pants parsing of argv, originally forked | ||
Object.keys(opts.alias || {}).forEach(function (key) { | ||
aliases[key] = [].concat(opts.alias[key]); | ||
// For "--option-name", also set argv.optionName | ||
aliases[key].concat(key).forEach(function (x) { | ||
if (/-/.test(x)) { | ||
var c = toCamelCase(x); | ||
aliases[key].push(c); | ||
newAliases[c] = true; | ||
} | ||
}); | ||
aliases[key].forEach(function (x) { | ||
aliases[x] = [key].concat(aliases[key].filter(function (y) { | ||
return x !== y; | ||
})); | ||
}); | ||
}); | ||
extendAliases(opts.key); | ||
extendAliases(opts.alias); | ||
var defaults = opts['default'] || {}; | ||
Object.keys(defaults || {}).forEach(function (key) { | ||
Object.keys(defaults).forEach(function (key) { | ||
if (/-/.test(key) && !opts.alias[key]) { | ||
@@ -337,2 +322,22 @@ var c = toCamelCase(key); | ||
// extend the aliases list with inferred aliases. | ||
function extendAliases (obj) { | ||
Object.keys(obj || {}).forEach(function(key) { | ||
aliases[key] = [].concat(opts.alias[key] || []); | ||
// For "--option-name", also set argv.optionName | ||
aliases[key].concat(key).forEach(function (x) { | ||
if (/-/.test(x)) { | ||
var c = toCamelCase(x); | ||
aliases[key].push(c); | ||
newAliases[c] = true; | ||
} | ||
}); | ||
aliases[key].forEach(function (x) { | ||
aliases[x] = [key].concat(aliases[key].filter(function (y) { | ||
return x !== y; | ||
})); | ||
}); | ||
}); | ||
} | ||
// check if a flag is set for any of a key's aliases. | ||
@@ -339,0 +344,0 @@ function checkAllAliases (key, flag) { |
@@ -138,2 +138,5 @@ // validation-type-stuff, missing params, | ||
}; | ||
self.getImplied = function() { | ||
return implied; | ||
} | ||
@@ -140,0 +143,0 @@ self.implications = function(argv) { |
{ | ||
"name": "yargs", | ||
"version": "3.2.1", | ||
"version": "3.3.1", | ||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -688,2 +688,38 @@ yargs | ||
.reset() | ||
-------- | ||
Reset the argument object built up so far. This is useful for | ||
creating nested command line interfaces. | ||
```js | ||
var yargs = require('./yargs') | ||
.usage('$0 command') | ||
.command('hello', 'hello command') | ||
.command('world', 'world command') | ||
.demand(1, 'must provide a valid command'), | ||
argv = yargs.argv, | ||
command = argv._[0]; | ||
if (command === 'hello') { | ||
yargs.reset() | ||
.usage('$0 hello') | ||
.help('h') | ||
.example('$0 hello', 'print the hello message!') | ||
.argv | ||
console.log('hello!'); | ||
} else if (command === 'world'){ | ||
yargs.reset() | ||
.usage('$0 world') | ||
.help('h') | ||
.example('$0 world', 'print the world message!') | ||
.argv | ||
console.log('world!'); | ||
} else { | ||
yargs.showHelp(); | ||
} | ||
``` | ||
.argv | ||
@@ -690,0 +726,0 @@ ----- |
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
61152
1132
824