Comparing version 3.11.0 to 3.12.0
## Change Log | ||
### v3.12.0 (2015/06/19 03:23 +00:00) | ||
- [#183](https://github.com/bcoe/yargs/pull/183) don't complete commands if they've already been completed (@tschaub) | ||
- [#181](https://github.com/bcoe/yargs/pull/181) various fixes for completion. (@bcoe, @tschaub) | ||
- [#182](https://github.com/bcoe/yargs/pull/182) you can now set a maximum # of of required arguments (@bcoe) | ||
### v3.11.0 (2015/06/15 05:15 +00:00) | ||
@@ -4,0 +9,0 @@ |
74
index.js
@@ -163,6 +163,14 @@ var assert = require('assert') | ||
var demanded = {} | ||
self.demand = self.required = self.require = function (keys, msg) { | ||
self.demand = self.required = self.require = function (keys, max, msg) { | ||
// you can optionally provide a 'max' key, | ||
// which will raise an exception if too many '_' | ||
// options are provided. | ||
if (typeof max !== 'number') { | ||
msg = max | ||
max = Infinity | ||
} | ||
if (typeof keys === 'number') { | ||
if (!demanded._) demanded._ = { count: 0, msg: null } | ||
demanded._.count += keys | ||
if (!demanded._) demanded._ = { count: 0, msg: null, max: max } | ||
demanded._.count = keys | ||
demanded._.msg = msg | ||
@@ -360,3 +368,3 @@ } else if (Array.isArray(keys)) { | ||
// register the completion command. | ||
completionCommand = cmd | ||
completionCommand = cmd || 'completion' | ||
completionOpt = completion.completionKey | ||
@@ -413,4 +421,13 @@ self.command(completionCommand, desc || 'generate bash completion script') | ||
// while building up the argv object, there | ||
// are two passes through the parser. If completion | ||
// is being performed short-circuit on the first pass. | ||
if (completionCommand && | ||
(process.argv.join(' ')).indexOf(completionOpt) !== -1 && | ||
!argv[completionOpt]) { | ||
return argv | ||
} | ||
// generate a completion script for adding to ~/.bashrc. | ||
if (completionCommand && ~argv._.indexOf(completionCommand)) { | ||
if (completionCommand && ~argv._.indexOf(completionCommand) && !argv[completionOpt]) { | ||
self.showCompletionScript() | ||
@@ -432,2 +449,19 @@ if (exitProcess) { | ||
// we must run completions first, a user might | ||
// want to complete the --help or --version option. | ||
if (completionOpt in argv) { | ||
// we allow for asynchronous completions, | ||
// e.g., loading in a list of commands from an API. | ||
completion.getCompletion(function (completions) { | ||
;(completions || []).forEach(function (completion) { | ||
console.log(completion) | ||
}) | ||
if (exitProcess) { | ||
process.exit(0) | ||
} | ||
}) | ||
return | ||
} | ||
Object.keys(argv).forEach(function (key) { | ||
@@ -444,28 +478,16 @@ if (key === helpOpt && argv[key]) { | ||
} | ||
} else if (key === completionOpt) { | ||
// we allow for asynchronous completions, | ||
// e.g., loading in a list of commands from an API. | ||
completion.getCompletion(function (completions) { | ||
;(completions || []).forEach(function (completion) { | ||
console.log(completion) | ||
}) | ||
if (exitProcess) { | ||
process.exit(0) | ||
} | ||
}) | ||
return | ||
} | ||
}) | ||
validation.nonOptionCount(argv) | ||
validation.missingArgumentValue(argv) | ||
validation.requiredArguments(argv) | ||
if (strict) { | ||
validation.unknownArguments(argv, aliases) | ||
// if we're executed via bash completion, don't | ||
// bother with validation. | ||
if (!argv[completionOpt]) { | ||
validation.nonOptionCount(argv) | ||
validation.missingArgumentValue(argv) | ||
validation.requiredArguments(argv) | ||
if (strict) validation.unknownArguments(argv, aliases) | ||
validation.customChecks(argv, aliases) | ||
validation.implications(argv) | ||
} | ||
validation.customChecks(argv, aliases) | ||
validation.implications(argv) | ||
setPlaceholderKeys(argv) | ||
@@ -472,0 +494,0 @@ |
@@ -34,3 +34,5 @@ var fs = require('fs') | ||
usage.getCommands().forEach(function (command) { | ||
completions.push(command[0]) | ||
if (previous.indexOf(command[0]) === -1) { | ||
completions.push(command[0]) | ||
} | ||
}) | ||
@@ -37,0 +39,0 @@ } |
@@ -10,10 +10,15 @@ // validation-type-stuff, missing params, | ||
var demanded = yargs.getDemanded() | ||
var _s = argv._.length | ||
if (demanded._ && argv._.length < demanded._.count) { | ||
if (demanded._ && (_s < demanded._.count || _s > demanded._.max)) { | ||
if (demanded._.msg !== undefined) { | ||
usage.fail(demanded._.msg) | ||
} else { | ||
} else if (_s < demanded._.count) { | ||
usage.fail('Not enough non-option arguments: got ' + | ||
argv._.length + ', need at least ' + demanded._.count | ||
) | ||
} else { | ||
usage.fail('Too many non-option arguments: got ' + | ||
argv._.length + ', maximum of ' + demanded._.max | ||
) | ||
} | ||
@@ -20,0 +25,0 @@ } |
{ | ||
"name": "yargs", | ||
"version": "3.11.0", | ||
"version": "3.12.0", | ||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -401,7 +401,9 @@ yargs | ||
.demand(key, [msg | boolean]) | ||
----------------------------- | ||
------------------------------ | ||
.require(key, [msg | boolean]) | ||
------------------------------ | ||
.required(key, [msg | boolean]) | ||
------------------------------- | ||
------------------------------ | ||
.demand(count, [max], [msg]) | ||
------------------------------ | ||
@@ -412,3 +414,4 @@ If `key` is a string, show the usage information and exit if `key` wasn't | ||
If `key` is a number, demand at least as many non-option arguments, which show | ||
up in `argv._`. | ||
up in `argv._`. A second number can also optionally be provided, which indicates | ||
the maximum number of non-option arguments. | ||
@@ -415,0 +418,0 @@ If `key` is an Array, demand each element. |
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
104622
1317
932