yargs 3.5.0 → 3.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/completion.sh.hbs +22 -0
- package/index.js +8 -7
- package/lib/completion.js +0 -5
- package/lib/usage.js +2 -6
- package/lib/validation.js +1 -1
- package/package.json +7 -1
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
###-begin-{{app_name}}-completions-###
|
|
2
|
+
#
|
|
3
|
+
# yargs command completion script
|
|
4
|
+
#
|
|
5
|
+
# Installation: {{app_path}} completion >> ~/.bashrc
|
|
6
|
+
# or {{app_path}} completion >> ~/.bash_profile on OSX.
|
|
7
|
+
#
|
|
8
|
+
_yargs_completions()
|
|
9
|
+
{
|
|
10
|
+
local cur_word args type_list
|
|
11
|
+
|
|
12
|
+
cur_word="${COMP_WORDS[COMP_CWORD]}"
|
|
13
|
+
args=$(printf "%s " "${COMP_WORDS[@]}")
|
|
14
|
+
|
|
15
|
+
# ask yargs to generate completions.
|
|
16
|
+
type_list=`{{app_path}} --get-yargs-completions $args`
|
|
17
|
+
|
|
18
|
+
COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) )
|
|
19
|
+
return 0
|
|
20
|
+
}
|
|
21
|
+
complete -F _yargs_completions {{app_name}}
|
|
22
|
+
###-end-{{app_name}}-completions-###
|
package/index.js
CHANGED
|
@@ -5,8 +5,7 @@ var assert = require('assert'),
|
|
|
5
5
|
Usage = require('./lib/usage'),
|
|
6
6
|
Validation = require('./lib/validation');
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
sigletonify(inst);
|
|
8
|
+
Argv(process.argv.slice(2));
|
|
10
9
|
|
|
11
10
|
var exports = module.exports = Argv;
|
|
12
11
|
function Argv (processArgs, cwd) {
|
|
@@ -360,8 +359,6 @@ function Argv (processArgs, cwd) {
|
|
|
360
359
|
// a function can be provided
|
|
361
360
|
if (fn) completion.registerFunction(fn);
|
|
362
361
|
|
|
363
|
-
if (!self.parsed) parseArgs(processArgs); // run parser, if it has not already been executed.
|
|
364
|
-
|
|
365
362
|
return self;
|
|
366
363
|
};
|
|
367
364
|
|
|
@@ -481,8 +478,12 @@ function rebase (base, dir) {
|
|
|
481
478
|
*/
|
|
482
479
|
function sigletonify(inst) {
|
|
483
480
|
Object.keys(inst).forEach(function (key) {
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
481
|
+
if (key === 'argv') {
|
|
482
|
+
Argv.__defineGetter__(key, inst.__lookupGetter__(key));
|
|
483
|
+
} else {
|
|
484
|
+
Argv[key] = typeof inst[key] == 'function'
|
|
485
|
+
? inst[key].bind(inst)
|
|
486
|
+
: inst[key];
|
|
487
|
+
}
|
|
487
488
|
});
|
|
488
489
|
}
|
package/lib/completion.js
CHANGED
|
@@ -15,11 +15,6 @@ module.exports = function (yargs, usage) {
|
|
|
15
15
|
previous = process.argv.slice(process.argv.indexOf('--' + self.completionKey) + 1),
|
|
16
16
|
argv = yargs.parse(previous);
|
|
17
17
|
|
|
18
|
-
fs.writeFileSync('./foo.txt', JSON.stringify({
|
|
19
|
-
previous: previous,
|
|
20
|
-
current: current
|
|
21
|
-
}), 'utf-8');
|
|
22
|
-
|
|
23
18
|
// a custom completion function can be provided
|
|
24
19
|
// to completion().
|
|
25
20
|
if (completionFunction) {
|
package/lib/usage.js
CHANGED
|
@@ -34,14 +34,10 @@ module.exports = function (yargs) {
|
|
|
34
34
|
f(msg);
|
|
35
35
|
});
|
|
36
36
|
} else {
|
|
37
|
-
if (showHelpOnFail)
|
|
38
|
-
yargs.showHelp("error");
|
|
39
|
-
}
|
|
37
|
+
if (showHelpOnFail) yargs.showHelp("error");
|
|
40
38
|
if (msg) console.error(msg);
|
|
41
39
|
if (failMessage) {
|
|
42
|
-
if (msg)
|
|
43
|
-
console.error("");
|
|
44
|
-
}
|
|
40
|
+
if (msg) console.error("");
|
|
45
41
|
console.error(failMessage);
|
|
46
42
|
}
|
|
47
43
|
if (yargs.getExitProcess()){
|
package/lib/validation.js
CHANGED
|
@@ -9,7 +9,7 @@ module.exports = function (yargs, usage) {
|
|
|
9
9
|
var demanded = yargs.getDemanded();
|
|
10
10
|
|
|
11
11
|
if (demanded._ && argv._.length < demanded._.count) {
|
|
12
|
-
if (demanded._.msg) {
|
|
12
|
+
if (demanded._.msg !== undefined) {
|
|
13
13
|
usage.fail(demanded._.msg);
|
|
14
14
|
} else {
|
|
15
15
|
usage.fail('Not enough non-option arguments: got '
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yargs",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.4",
|
|
4
4
|
"description": "Light-weight option parsing with an argv hash. No optstrings attached.",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.js",
|
|
8
8
|
"lib",
|
|
9
|
+
"completion.sh.hbs",
|
|
9
10
|
"LICENSE"
|
|
10
11
|
],
|
|
11
12
|
"dependencies": {
|
|
@@ -58,6 +59,11 @@
|
|
|
58
59
|
"url": "http://CodeTunnel.com"
|
|
59
60
|
},
|
|
60
61
|
"contributors": [
|
|
62
|
+
{
|
|
63
|
+
"name": "Benjamin Coe",
|
|
64
|
+
"email": "ben@npmjs.com",
|
|
65
|
+
"url": "https://github.com/bcoe"
|
|
66
|
+
},
|
|
61
67
|
{
|
|
62
68
|
"name": "Chris Needham",
|
|
63
69
|
"email": "chris@chrisneedham.com",
|