commander 2.10.0 → 2.12.2
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/{History.md → CHANGELOG.md} +45 -0
- package/Readme.md +23 -5
- package/index.js +59 -30
- package/package.json +13 -13
- package/typings/index.d.ts +295 -0
|
@@ -1,6 +1,51 @@
|
|
|
1
1
|
|
|
2
|
+
2.12.2 / 2017-11-28
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* fix: typings are not shipped
|
|
6
|
+
|
|
7
|
+
2.12.1 / 2017-11-23
|
|
8
|
+
==================
|
|
9
|
+
|
|
10
|
+
* Move @types/node to dev dependency
|
|
11
|
+
|
|
12
|
+
2.12.0 / 2017-11-22
|
|
13
|
+
==================
|
|
14
|
+
|
|
15
|
+
* add attributeName() method to Option objects
|
|
16
|
+
* Documentation updated for options with --no prefix
|
|
17
|
+
* typings: `outputHelp` takes a string as the first parameter
|
|
18
|
+
* typings: use overloads
|
|
19
|
+
* feat(typings): update to match js api
|
|
20
|
+
* Print default value in option help
|
|
21
|
+
* Fix translation error
|
|
22
|
+
* Fail when using same command and alias (#491)
|
|
23
|
+
* feat(typings): add help callback
|
|
24
|
+
* fix bug when description is add after command with options (#662)
|
|
25
|
+
* Format js code
|
|
26
|
+
* Rename History.md to CHANGELOG.md (#668)
|
|
27
|
+
* feat(typings): add typings to support TypeScript (#646)
|
|
28
|
+
* use current node
|
|
29
|
+
|
|
30
|
+
2.11.0 / 2017-07-03
|
|
31
|
+
==================
|
|
32
|
+
|
|
33
|
+
* Fix help section order and padding (#652)
|
|
34
|
+
* feature: support for signals to subcommands (#632)
|
|
35
|
+
* Fixed #37, --help should not display first (#447)
|
|
36
|
+
* Fix translation errors. (#570)
|
|
37
|
+
* Add package-lock.json
|
|
38
|
+
* Remove engines
|
|
39
|
+
* Upgrade package version
|
|
40
|
+
* Prefix events to prevent conflicts between commands and options (#494)
|
|
41
|
+
* Removing dependency on graceful-readlink
|
|
42
|
+
* Support setting name in #name function and make it chainable
|
|
43
|
+
* Add .vscode directory to .gitignore (Visual Studio Code metadata)
|
|
44
|
+
* Updated link to ruby commander in readme files
|
|
45
|
+
|
|
2
46
|
2.10.0 / 2017-06-19
|
|
3
47
|
==================
|
|
48
|
+
|
|
4
49
|
* Update .travis.yml. drop support for older node.js versions.
|
|
5
50
|
* Fix require arguments in README.md
|
|
6
51
|
* On SemVer you do not start from 0.0.1
|
package/Readme.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://www.npmjs.org/package/commander)
|
|
7
7
|
[](https://gitter.im/tj/commander.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
|
8
8
|
|
|
9
|
-
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/
|
|
9
|
+
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander).
|
|
10
10
|
[API documentation](http://tj.github.com/commander.js/)
|
|
11
11
|
|
|
12
12
|
|
|
@@ -44,6 +44,25 @@ console.log(' - %s cheese', program.cheese);
|
|
|
44
44
|
|
|
45
45
|
Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.
|
|
46
46
|
|
|
47
|
+
Note that multi-word options starting with `--no` prefix negate the boolean value of the following word. For example, `--no-sauce` sets the value of `program.sauce` to false.
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
#!/usr/bin/env node
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Module dependencies.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
var program = require('commander');
|
|
57
|
+
|
|
58
|
+
program
|
|
59
|
+
.option('--no-sauce', 'Remove sauce')
|
|
60
|
+
.parse(process.argv);
|
|
61
|
+
|
|
62
|
+
console.log('you ordered a pizza');
|
|
63
|
+
if (program.sauce) console.log(' with sauce');
|
|
64
|
+
else console.log(' without sauce');
|
|
65
|
+
```
|
|
47
66
|
|
|
48
67
|
## Coercion
|
|
49
68
|
|
|
@@ -285,9 +304,9 @@ program
|
|
|
285
304
|
.command('getstream [url]', 'get stream URL')
|
|
286
305
|
.parse(process.argv);
|
|
287
306
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
307
|
+
if (!process.argv.slice(2).length) {
|
|
308
|
+
program.outputHelp(make_red);
|
|
309
|
+
}
|
|
291
310
|
|
|
292
311
|
function make_red(txt) {
|
|
293
312
|
return colors.red(txt); //display the help text in red on the console
|
|
@@ -349,4 +368,3 @@ More Demos can be found in the [examples](https://github.com/tj/commander.js/tre
|
|
|
349
368
|
## License
|
|
350
369
|
|
|
351
370
|
MIT
|
|
352
|
-
|
package/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
var EventEmitter = require('events').EventEmitter;
|
|
6
6
|
var spawn = require('child_process').spawn;
|
|
7
|
-
var readlink = require('graceful-readlink').readlinkSync;
|
|
8
7
|
var path = require('path');
|
|
9
8
|
var dirname = path.dirname;
|
|
10
9
|
var basename = path.basename;
|
|
@@ -60,6 +59,18 @@ Option.prototype.name = function() {
|
|
|
60
59
|
.replace('no-', '');
|
|
61
60
|
};
|
|
62
61
|
|
|
62
|
+
/**
|
|
63
|
+
* Return option name, in a camelcase format that can be used
|
|
64
|
+
* as a object attribute key.
|
|
65
|
+
*
|
|
66
|
+
* @return {String}
|
|
67
|
+
* @api private
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
Option.prototype.attributeName = function() {
|
|
71
|
+
return camelcase( this.name() );
|
|
72
|
+
};
|
|
73
|
+
|
|
63
74
|
/**
|
|
64
75
|
* Check if `arg` matches the short or long flag.
|
|
65
76
|
*
|
|
@@ -156,6 +167,10 @@ Command.prototype.__proto__ = EventEmitter.prototype;
|
|
|
156
167
|
*/
|
|
157
168
|
|
|
158
169
|
Command.prototype.command = function(name, desc, opts) {
|
|
170
|
+
if(typeof desc === 'object' && desc !== null){
|
|
171
|
+
opts = desc;
|
|
172
|
+
desc = null;
|
|
173
|
+
}
|
|
159
174
|
opts = opts || {};
|
|
160
175
|
var args = name.split(/ +/);
|
|
161
176
|
var cmd = new Command(args.shift());
|
|
@@ -166,7 +181,6 @@ Command.prototype.command = function(name, desc, opts) {
|
|
|
166
181
|
this._execs[cmd._name] = true;
|
|
167
182
|
if (opts.isDefault) this.defaultExecutable = cmd._name;
|
|
168
183
|
}
|
|
169
|
-
|
|
170
184
|
cmd._noHelp = !!opts.noHelp;
|
|
171
185
|
this.commands.push(cmd);
|
|
172
186
|
cmd.parseExpectedArgs(args);
|
|
@@ -302,8 +316,8 @@ Command.prototype.action = function(fn) {
|
|
|
302
316
|
};
|
|
303
317
|
var parent = this.parent || this;
|
|
304
318
|
var name = parent === this ? '*' : this._name;
|
|
305
|
-
parent.on(name, listener);
|
|
306
|
-
if (this._alias) parent.on(this._alias, listener);
|
|
319
|
+
parent.on('command:' + name, listener);
|
|
320
|
+
if (this._alias) parent.on('command:' + this._alias, listener);
|
|
307
321
|
return this;
|
|
308
322
|
};
|
|
309
323
|
|
|
@@ -360,7 +374,7 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
|
|
|
360
374
|
var self = this
|
|
361
375
|
, option = new Option(flags, description)
|
|
362
376
|
, oname = option.name()
|
|
363
|
-
, name =
|
|
377
|
+
, name = option.attributeName();
|
|
364
378
|
|
|
365
379
|
// default as 3rd arg
|
|
366
380
|
if (typeof fn != 'function') {
|
|
@@ -382,7 +396,10 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
|
|
|
382
396
|
// when --no-* we make sure default is true
|
|
383
397
|
if (false == option.bool) defaultValue = true;
|
|
384
398
|
// preassign only if we have a default
|
|
385
|
-
if (undefined !== defaultValue)
|
|
399
|
+
if (undefined !== defaultValue) {
|
|
400
|
+
self[name] = defaultValue;
|
|
401
|
+
option.defaultValue = defaultValue;
|
|
402
|
+
}
|
|
386
403
|
}
|
|
387
404
|
|
|
388
405
|
// register the option
|
|
@@ -390,7 +407,7 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
|
|
|
390
407
|
|
|
391
408
|
// when it's passed assign the value
|
|
392
409
|
// and conditionally invoke the callback
|
|
393
|
-
this.on(oname, function(val) {
|
|
410
|
+
this.on('option:' + oname, function(val) {
|
|
394
411
|
// coercion
|
|
395
412
|
if (null !== val && fn) val = fn(val, undefined === self[name]
|
|
396
413
|
? defaultValue
|
|
@@ -513,7 +530,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
513
530
|
// In case of globally installed, get the base dir where executable
|
|
514
531
|
// subcommand file should be located at
|
|
515
532
|
var baseDir
|
|
516
|
-
, link =
|
|
533
|
+
, link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
|
|
517
534
|
|
|
518
535
|
// when symbolink is relative path
|
|
519
536
|
if (link !== f && link.charAt(0) !== '/') {
|
|
@@ -542,7 +559,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
542
559
|
// add executable arguments to spawn
|
|
543
560
|
args = (process.execArgv || []).concat(args);
|
|
544
561
|
|
|
545
|
-
proc = spawn(
|
|
562
|
+
proc = spawn(process.argv[0], args, { stdio: 'inherit', customFds: [0, 1, 2] });
|
|
546
563
|
} else {
|
|
547
564
|
proc = spawn(bin, args, { stdio: 'inherit', customFds: [0, 1, 2] });
|
|
548
565
|
}
|
|
@@ -551,6 +568,14 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
|
|
|
551
568
|
proc = spawn(process.execPath, args, { stdio: 'inherit'});
|
|
552
569
|
}
|
|
553
570
|
|
|
571
|
+
var signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
|
|
572
|
+
signals.forEach(function(signal) {
|
|
573
|
+
process.on(signal, function(){
|
|
574
|
+
if ((proc.killed === false) && (proc.exitCode === null)){
|
|
575
|
+
proc.kill(signal);
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
});
|
|
554
579
|
proc.on('close', process.exit.bind(process));
|
|
555
580
|
proc.on('error', function(err) {
|
|
556
581
|
if (err.code == "ENOENT") {
|
|
@@ -624,10 +649,10 @@ Command.prototype.parseArgs = function(args, unknown) {
|
|
|
624
649
|
|
|
625
650
|
if (args.length) {
|
|
626
651
|
name = args[0];
|
|
627
|
-
if (this.listeners(name).length) {
|
|
628
|
-
this.emit(args.shift(), args, unknown);
|
|
652
|
+
if (this.listeners('command:' + name).length) {
|
|
653
|
+
this.emit('command:' + args.shift(), args, unknown);
|
|
629
654
|
} else {
|
|
630
|
-
this.emit('
|
|
655
|
+
this.emit('command:*', args);
|
|
631
656
|
}
|
|
632
657
|
} else {
|
|
633
658
|
outputHelpIfNecessary(this, unknown);
|
|
@@ -700,7 +725,7 @@ Command.prototype.parseOptions = function(argv) {
|
|
|
700
725
|
if (option.required) {
|
|
701
726
|
arg = argv[++i];
|
|
702
727
|
if (null == arg) return this.optionMissingArgument(option);
|
|
703
|
-
this.emit(option.name(), arg);
|
|
728
|
+
this.emit('option:' + option.name(), arg);
|
|
704
729
|
// optional arg
|
|
705
730
|
} else if (option.optional) {
|
|
706
731
|
arg = argv[i+1];
|
|
@@ -709,10 +734,10 @@ Command.prototype.parseOptions = function(argv) {
|
|
|
709
734
|
} else {
|
|
710
735
|
++i;
|
|
711
736
|
}
|
|
712
|
-
this.emit(option.name(), arg);
|
|
737
|
+
this.emit('option:' + option.name(), arg);
|
|
713
738
|
// bool
|
|
714
739
|
} else {
|
|
715
|
-
this.emit(option.name());
|
|
740
|
+
this.emit('option:' + option.name());
|
|
716
741
|
}
|
|
717
742
|
continue;
|
|
718
743
|
}
|
|
@@ -748,7 +773,7 @@ Command.prototype.opts = function() {
|
|
|
748
773
|
, len = this.options.length;
|
|
749
774
|
|
|
750
775
|
for (var i = 0 ; i < len; i++) {
|
|
751
|
-
var key =
|
|
776
|
+
var key = this.options[i].attributeName();
|
|
752
777
|
result[key] = key === 'version' ? this._version : this[key];
|
|
753
778
|
}
|
|
754
779
|
return result;
|
|
@@ -833,7 +858,7 @@ Command.prototype.version = function(str, flags) {
|
|
|
833
858
|
this._version = str;
|
|
834
859
|
flags = flags || '-V, --version';
|
|
835
860
|
this.option(flags, 'output the version number');
|
|
836
|
-
this.on('version', function() {
|
|
861
|
+
this.on('option:version', function() {
|
|
837
862
|
process.stdout.write(str + '\n');
|
|
838
863
|
process.exit(0);
|
|
839
864
|
});
|
|
@@ -870,6 +895,8 @@ Command.prototype.alias = function(alias) {
|
|
|
870
895
|
|
|
871
896
|
if (arguments.length === 0) return command._alias;
|
|
872
897
|
|
|
898
|
+
if (alias === command._name) throw new Error('Command alias can\'t be the same as its name');
|
|
899
|
+
|
|
873
900
|
command._alias = alias;
|
|
874
901
|
return this;
|
|
875
902
|
};
|
|
@@ -898,15 +925,17 @@ Command.prototype.usage = function(str) {
|
|
|
898
925
|
};
|
|
899
926
|
|
|
900
927
|
/**
|
|
901
|
-
* Get the name of the command
|
|
928
|
+
* Get or set the name of the command
|
|
902
929
|
*
|
|
903
|
-
* @param {String}
|
|
930
|
+
* @param {String} str
|
|
904
931
|
* @return {String|Command}
|
|
905
932
|
* @api public
|
|
906
933
|
*/
|
|
907
934
|
|
|
908
|
-
Command.prototype.name = function() {
|
|
909
|
-
return this._name;
|
|
935
|
+
Command.prototype.name = function(str) {
|
|
936
|
+
if (0 === arguments.length) return this._name;
|
|
937
|
+
this._name = str;
|
|
938
|
+
return this;
|
|
910
939
|
};
|
|
911
940
|
|
|
912
941
|
/**
|
|
@@ -932,12 +961,12 @@ Command.prototype.largestOptionLength = function() {
|
|
|
932
961
|
Command.prototype.optionHelp = function() {
|
|
933
962
|
var width = this.largestOptionLength();
|
|
934
963
|
|
|
935
|
-
//
|
|
936
|
-
return
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
964
|
+
// Append the help information
|
|
965
|
+
return this.options.map(function(option) {
|
|
966
|
+
return pad(option.flags, width) + ' ' + option.description
|
|
967
|
+
+ (option.defaultValue !== undefined ? ' (default: ' + option.defaultValue + ')' : '');
|
|
968
|
+
}).concat([pad('-h, --help', width) + ' ' + 'output usage information'])
|
|
969
|
+
.join('\n');
|
|
941
970
|
};
|
|
942
971
|
|
|
943
972
|
/**
|
|
@@ -1013,17 +1042,17 @@ Command.prototype.helpInformation = function() {
|
|
|
1013
1042
|
if (commandHelp) cmds = [commandHelp];
|
|
1014
1043
|
|
|
1015
1044
|
var options = [
|
|
1016
|
-
'
|
|
1045
|
+
''
|
|
1046
|
+
, ' Options:'
|
|
1017
1047
|
, ''
|
|
1018
1048
|
, '' + this.optionHelp().replace(/^/gm, ' ')
|
|
1019
1049
|
, ''
|
|
1020
|
-
, ''
|
|
1021
1050
|
];
|
|
1022
1051
|
|
|
1023
1052
|
return usage
|
|
1024
|
-
.concat(cmds)
|
|
1025
1053
|
.concat(desc)
|
|
1026
1054
|
.concat(options)
|
|
1055
|
+
.concat(cmds)
|
|
1027
1056
|
.join('\n');
|
|
1028
1057
|
};
|
|
1029
1058
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commander",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.2",
|
|
4
4
|
"description": "the complete solution for node.js command-line programs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"commander",
|
|
@@ -14,21 +14,21 @@
|
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "https://github.com/tj/commander.js.git"
|
|
16
16
|
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"should": ">= 0.0.1 <9.0.0",
|
|
19
|
-
"sinon": ">=1.17.1"
|
|
20
|
-
},
|
|
21
17
|
"scripts": {
|
|
22
|
-
"test": "make test"
|
|
18
|
+
"test": "make test && npm run test-typings",
|
|
19
|
+
"test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json"
|
|
23
20
|
},
|
|
24
21
|
"main": "index",
|
|
25
|
-
"engines": {
|
|
26
|
-
"node": ">= 0.6.x"
|
|
27
|
-
},
|
|
28
22
|
"files": [
|
|
29
|
-
"index.js"
|
|
23
|
+
"index.js",
|
|
24
|
+
"typings/index.d.ts"
|
|
30
25
|
],
|
|
31
|
-
"dependencies": {
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
"dependencies": {},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^7.0.48",
|
|
29
|
+
"should": "^11.2.1",
|
|
30
|
+
"sinon": "^2.4.1",
|
|
31
|
+
"typescript": "^2.6.2"
|
|
32
|
+
},
|
|
33
|
+
"typings": "typings/index.d.ts"
|
|
34
34
|
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
// Project: https://github.com/visionmedia/commander.js
|
|
2
|
+
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>
|
|
3
|
+
|
|
4
|
+
declare class Option {
|
|
5
|
+
flags: string;
|
|
6
|
+
required: boolean;
|
|
7
|
+
optional: boolean;
|
|
8
|
+
bool: boolean;
|
|
9
|
+
short?: string;
|
|
10
|
+
long: string;
|
|
11
|
+
description: string;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} flags
|
|
17
|
+
* @param {string} [description]
|
|
18
|
+
*/
|
|
19
|
+
constructor(flags: string, description?: string);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class Command extends NodeJS.EventEmitter {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
|
|
25
|
+
args: string[];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Initialize a new `Command`.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} [name]
|
|
31
|
+
*/
|
|
32
|
+
constructor(name?: string);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Set the program version to `str`.
|
|
36
|
+
*
|
|
37
|
+
* This method auto-registers the "-V, --version" flag
|
|
38
|
+
* which will print the version number when passed.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} str
|
|
41
|
+
* @param {string} [flags]
|
|
42
|
+
* @returns {Command} for chaining
|
|
43
|
+
*/
|
|
44
|
+
version(str: string, flags?: string): Command;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Add command `name`.
|
|
48
|
+
*
|
|
49
|
+
* The `.action()` callback is invoked when the
|
|
50
|
+
* command `name` is specified via __ARGV__,
|
|
51
|
+
* and the remaining arguments are applied to the
|
|
52
|
+
* function for access.
|
|
53
|
+
*
|
|
54
|
+
* When the `name` is "*" an un-matched command
|
|
55
|
+
* will be passed as the first arg, followed by
|
|
56
|
+
* the rest of __ARGV__ remaining.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* program
|
|
60
|
+
* .version('0.0.1')
|
|
61
|
+
* .option('-C, --chdir <path>', 'change the working directory')
|
|
62
|
+
* .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
|
|
63
|
+
* .option('-T, --no-tests', 'ignore test hook')
|
|
64
|
+
*
|
|
65
|
+
* program
|
|
66
|
+
* .command('setup')
|
|
67
|
+
* .description('run remote setup commands')
|
|
68
|
+
* .action(function() {
|
|
69
|
+
* console.log('setup');
|
|
70
|
+
* });
|
|
71
|
+
*
|
|
72
|
+
* program
|
|
73
|
+
* .command('exec <cmd>')
|
|
74
|
+
* .description('run the given remote command')
|
|
75
|
+
* .action(function(cmd) {
|
|
76
|
+
* console.log('exec "%s"', cmd);
|
|
77
|
+
* });
|
|
78
|
+
*
|
|
79
|
+
* program
|
|
80
|
+
* .command('teardown <dir> [otherDirs...]')
|
|
81
|
+
* .description('run teardown commands')
|
|
82
|
+
* .action(function(dir, otherDirs) {
|
|
83
|
+
* console.log('dir "%s"', dir);
|
|
84
|
+
* if (otherDirs) {
|
|
85
|
+
* otherDirs.forEach(function (oDir) {
|
|
86
|
+
* console.log('dir "%s"', oDir);
|
|
87
|
+
* });
|
|
88
|
+
* }
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* program
|
|
92
|
+
* .command('*')
|
|
93
|
+
* .description('deploy the given env')
|
|
94
|
+
* .action(function(env) {
|
|
95
|
+
* console.log('deploying "%s"', env);
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* program.parse(process.argv);
|
|
99
|
+
*
|
|
100
|
+
* @param {string} name
|
|
101
|
+
* @param {string} [desc] for git-style sub-commands
|
|
102
|
+
* @param {CommandOptions} [opts] command options
|
|
103
|
+
* @returns {Command} the new command
|
|
104
|
+
*/
|
|
105
|
+
command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Define argument syntax for the top-level command.
|
|
109
|
+
*
|
|
110
|
+
* @param {string} desc
|
|
111
|
+
* @returns {Command} for chaining
|
|
112
|
+
*/
|
|
113
|
+
arguments(desc: string): Command;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parse expected `args`.
|
|
117
|
+
*
|
|
118
|
+
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
|
|
119
|
+
*
|
|
120
|
+
* @param {string[]} args
|
|
121
|
+
* @returns {Command} for chaining
|
|
122
|
+
*/
|
|
123
|
+
parseExpectedArgs(args: string[]): Command;
|
|
124
|
+
/**
|
|
125
|
+
* Register callback `fn` for the command.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* program
|
|
129
|
+
* .command('help')
|
|
130
|
+
* .description('display verbose help')
|
|
131
|
+
* .action(function() {
|
|
132
|
+
* // output help here
|
|
133
|
+
* });
|
|
134
|
+
*
|
|
135
|
+
* @param {(...args: any[]) => void} fn
|
|
136
|
+
* @returns {Command} for chaining
|
|
137
|
+
*/
|
|
138
|
+
action(fn: (...args: any[]) => void): Command;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Define option with `flags`, `description` and optional
|
|
142
|
+
* coercion `fn`.
|
|
143
|
+
*
|
|
144
|
+
* The `flags` string should contain both the short and long flags,
|
|
145
|
+
* separated by comma, a pipe or space. The following are all valid
|
|
146
|
+
* all will output this way when `--help` is used.
|
|
147
|
+
*
|
|
148
|
+
* "-p, --pepper"
|
|
149
|
+
* "-p|--pepper"
|
|
150
|
+
* "-p --pepper"
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // simple boolean defaulting to false
|
|
154
|
+
* program.option('-p, --pepper', 'add pepper');
|
|
155
|
+
*
|
|
156
|
+
* --pepper
|
|
157
|
+
* program.pepper
|
|
158
|
+
* // => Boolean
|
|
159
|
+
*
|
|
160
|
+
* // simple boolean defaulting to true
|
|
161
|
+
* program.option('-C, --no-cheese', 'remove cheese');
|
|
162
|
+
*
|
|
163
|
+
* program.cheese
|
|
164
|
+
* // => true
|
|
165
|
+
*
|
|
166
|
+
* --no-cheese
|
|
167
|
+
* program.cheese
|
|
168
|
+
* // => false
|
|
169
|
+
*
|
|
170
|
+
* // required argument
|
|
171
|
+
* program.option('-C, --chdir <path>', 'change the working directory');
|
|
172
|
+
*
|
|
173
|
+
* --chdir /tmp
|
|
174
|
+
* program.chdir
|
|
175
|
+
* // => "/tmp"
|
|
176
|
+
*
|
|
177
|
+
* // optional argument
|
|
178
|
+
* program.option('-c, --cheese [type]', 'add cheese [marble]');
|
|
179
|
+
*
|
|
180
|
+
* @param {string} flags
|
|
181
|
+
* @param {string} [description]
|
|
182
|
+
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
|
|
183
|
+
* @param {*} [defaultValue]
|
|
184
|
+
* @returns {Command} for chaining
|
|
185
|
+
*/
|
|
186
|
+
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
|
|
187
|
+
option(flags: string, description?: string, defaultValue?: any): Command;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Allow unknown options on the command line.
|
|
191
|
+
*
|
|
192
|
+
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
|
|
193
|
+
* @returns {Command} for chaining
|
|
194
|
+
*/
|
|
195
|
+
allowUnknownOption(arg?: boolean): Command;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Parse `argv`, settings options and invoking commands when defined.
|
|
199
|
+
*
|
|
200
|
+
* @param {string[]} argv
|
|
201
|
+
* @returns {Command} for chaining
|
|
202
|
+
*/
|
|
203
|
+
parse(argv: string[]): Command;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Parse options from `argv` returning `argv` void of these options.
|
|
207
|
+
*
|
|
208
|
+
* @param {string[]} argv
|
|
209
|
+
* @returns {ParseOptionsResult}
|
|
210
|
+
*/
|
|
211
|
+
parseOptions(argv: string[]): commander.ParseOptionsResult;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Return an object containing options as key-value pairs
|
|
215
|
+
*
|
|
216
|
+
* @returns {{[key: string]: string}}
|
|
217
|
+
*/
|
|
218
|
+
opts(): { [key: string]: string };
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Set the description to `str`.
|
|
222
|
+
*
|
|
223
|
+
* @param {string} str
|
|
224
|
+
* @return {(Command | string)}
|
|
225
|
+
*/
|
|
226
|
+
description(str: string): Command;
|
|
227
|
+
description(): string;
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Set an alias for the command.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} alias
|
|
233
|
+
* @return {(Command | string)}
|
|
234
|
+
*/
|
|
235
|
+
alias(alias: string): Command;
|
|
236
|
+
alias(): string;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Set or get the command usage.
|
|
240
|
+
*
|
|
241
|
+
* @param {string} str
|
|
242
|
+
* @return {(Command | string)}
|
|
243
|
+
*/
|
|
244
|
+
usage(str: string): Command;
|
|
245
|
+
usage(): string;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Set the name of the command.
|
|
249
|
+
*
|
|
250
|
+
* @param {string} str
|
|
251
|
+
* @return {Command}
|
|
252
|
+
*/
|
|
253
|
+
name(str: string): Command;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Get the name of the command.
|
|
257
|
+
*
|
|
258
|
+
* @return {string}
|
|
259
|
+
*/
|
|
260
|
+
name(): string;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Output help information for this command.
|
|
264
|
+
*
|
|
265
|
+
* @param {(str: string) => string} [cb]
|
|
266
|
+
*/
|
|
267
|
+
outputHelp(cb?: (str: string) => string): void;
|
|
268
|
+
|
|
269
|
+
/** Output help information and exit. */
|
|
270
|
+
help(): void;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
declare namespace commander {
|
|
274
|
+
|
|
275
|
+
interface CommandOptions {
|
|
276
|
+
noHelp?: boolean;
|
|
277
|
+
isDefault?: boolean;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
interface ParseOptionsResult {
|
|
281
|
+
args: string[];
|
|
282
|
+
unknown: string[];
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
interface CommanderStatic extends Command {
|
|
286
|
+
Command: typeof Command;
|
|
287
|
+
Option: typeof Option;
|
|
288
|
+
CommandOptions: CommandOptions;
|
|
289
|
+
ParseOptionsResult: ParseOptionsResult;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
declare const commander: commander.CommanderStatic;
|
|
295
|
+
export = commander;
|