commander 2.12.1 → 2.14.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,33 @@
1
1
 
2
+ 2.14.1 / 2018-02-07
3
+ ==================
4
+
5
+ * Fix typing of help function
6
+
7
+ 2.14.0 / 2018-02-05
8
+ ==================
9
+
10
+ * only register the option:version event once
11
+ * Fixes issue #727: Passing empty string for option on command is set to undefined
12
+ * enable eqeqeq rule
13
+ * resolves #754 add linter configuration to project
14
+ * resolves #560 respect custom name for version option
15
+ * document how to override the version flag
16
+ * document using options per command
17
+
18
+ 2.13.0 / 2018-01-09
19
+ ==================
20
+
21
+ * Do not print default for --no-
22
+ * remove trailing spaces in command help
23
+ * Update CI's Node.js to LTS and latest version
24
+ * typedefs: Command and Option types added to commander namespace
25
+
26
+ 2.12.2 / 2017-11-28
27
+ ==================
28
+
29
+ * fix: typings are not shipped
30
+
2
31
  2.12.1 / 2017-11-23
3
32
  ==================
4
33
 
package/Readme.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ## Option parsing
18
18
 
19
- Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
19
+ Options with commander are defined with the `.option()` method, also serving as documentation for the options. The example below parses args and options from `process.argv`, leaving remaining args as the `program.args` array which were not consumed by options.
20
20
 
21
21
  ```js
22
22
  #!/usr/bin/env node
@@ -42,7 +42,7 @@ if (program.bbqSauce) console.log(' - bbq');
42
42
  console.log(' - %s cheese', program.cheese);
43
43
  ```
44
44
 
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.
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
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
48
 
@@ -64,6 +64,44 @@ if (program.sauce) console.log(' with sauce');
64
64
  else console.log(' without sauce');
65
65
  ```
66
66
 
67
+ ## Version option
68
+
69
+ Calling the `version` implicitly adds the `-V` and `--version` options to the command.
70
+ When either of these options is present, the command prints the version number and exits.
71
+
72
+ $ ./examples/pizza -V
73
+ 0.0.1
74
+
75
+ If you want your program to respond to the `-v` option instead of the `-V` option, simply pass custom flags to the `version` method using the same syntax as the `option` method.
76
+
77
+ ```js
78
+ program
79
+ .version('0.0.1', '-v, --version')
80
+ ```
81
+
82
+ The version flags can be named anything, but the long option is required.
83
+
84
+ ## Command-specific options
85
+
86
+ You can attach options to a command.
87
+
88
+ ```js
89
+ #!/usr/bin/env node
90
+
91
+ var program = require('commander');
92
+
93
+ program
94
+ .command('rm <dir>')
95
+ .option('-r, --recursive', 'Remove recursively')
96
+ .action(function (dir, cmd) {
97
+ console.log('remove ' + dir + (cmd.recursive ? ' recursively' : ''))
98
+ })
99
+
100
+ program.parse(process.argv)
101
+ ```
102
+
103
+ A command's options are validated when the command is used. Any unknown options will be reported as an error. However, if an action-based command does not define an action, then the options are not validated.
104
+
67
105
  ## Coercion
68
106
 
69
107
  ```js
package/index.js CHANGED
@@ -9,6 +9,12 @@ var dirname = path.dirname;
9
9
  var basename = path.basename;
10
10
  var fs = require('fs');
11
11
 
12
+ /**
13
+ * Inherit `Command` from `EventEmitter.prototype`.
14
+ */
15
+
16
+ require('util').inherits(Command, EventEmitter);
17
+
12
18
  /**
13
19
  * Expose the root command.
14
20
  */
@@ -68,7 +74,7 @@ Option.prototype.name = function() {
68
74
  */
69
75
 
70
76
  Option.prototype.attributeName = function() {
71
- return camelcase( this.name() );
77
+ return camelcase(this.name());
72
78
  };
73
79
 
74
80
  /**
@@ -80,7 +86,7 @@ Option.prototype.attributeName = function() {
80
86
  */
81
87
 
82
88
  Option.prototype.is = function(arg) {
83
- return arg == this.short || arg == this.long;
89
+ return this.short === arg || this.long === arg;
84
90
  };
85
91
 
86
92
  /**
@@ -99,12 +105,6 @@ function Command(name) {
99
105
  this._name = name || '';
100
106
  }
101
107
 
102
- /**
103
- * Inherit from `EventEmitter.prototype`.
104
- */
105
-
106
- Command.prototype.__proto__ = EventEmitter.prototype;
107
-
108
108
  /**
109
109
  * Add command `name`.
110
110
  *
@@ -167,7 +167,7 @@ Command.prototype.__proto__ = EventEmitter.prototype;
167
167
  */
168
168
 
169
169
  Command.prototype.command = function(name, desc, opts) {
170
- if(typeof desc === 'object' && desc !== null){
170
+ if (typeof desc === 'object' && desc !== null) {
171
171
  opts = desc;
172
172
  desc = null;
173
173
  }
@@ -196,7 +196,7 @@ Command.prototype.command = function(name, desc, opts) {
196
196
  * @api public
197
197
  */
198
198
 
199
- Command.prototype.arguments = function (desc) {
199
+ Command.prototype.arguments = function(desc) {
200
200
  return this.parseExpectedArgs(desc.split(/ +/));
201
201
  };
202
202
 
@@ -292,7 +292,7 @@ Command.prototype.action = function(fn) {
292
292
  if (parsed.args.length) args = parsed.args.concat(args);
293
293
 
294
294
  self._args.forEach(function(arg, i) {
295
- if (arg.required && null == args[i]) {
295
+ if (arg.required && args[i] == null) {
296
296
  self.missingArgument(arg.name);
297
297
  } else if (arg.variadic) {
298
298
  if (i !== self._args.length - 1) {
@@ -371,32 +371,31 @@ Command.prototype.action = function(fn) {
371
371
  */
372
372
 
373
373
  Command.prototype.option = function(flags, description, fn, defaultValue) {
374
- var self = this
375
- , option = new Option(flags, description)
376
- , oname = option.name()
377
- , name = option.attributeName();
374
+ var self = this,
375
+ option = new Option(flags, description),
376
+ oname = option.name(),
377
+ name = option.attributeName();
378
378
 
379
379
  // default as 3rd arg
380
- if (typeof fn != 'function') {
380
+ if (typeof fn !== 'function') {
381
381
  if (fn instanceof RegExp) {
382
382
  var regex = fn;
383
383
  fn = function(val, def) {
384
384
  var m = regex.exec(val);
385
385
  return m ? m[0] : def;
386
- }
387
- }
388
- else {
386
+ };
387
+ } else {
389
388
  defaultValue = fn;
390
389
  fn = null;
391
390
  }
392
391
  }
393
392
 
394
393
  // preassign default value only for --no-*, [optional], or <required>
395
- if (false == option.bool || option.optional || option.required) {
394
+ if (!option.bool || option.optional || option.required) {
396
395
  // when --no-* we make sure default is true
397
- if (false == option.bool) defaultValue = true;
396
+ if (!option.bool) defaultValue = true;
398
397
  // preassign only if we have a default
399
- if (undefined !== defaultValue) {
398
+ if (defaultValue !== undefined) {
400
399
  self[name] = defaultValue;
401
400
  option.defaultValue = defaultValue;
402
401
  }
@@ -409,21 +408,21 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
409
408
  // and conditionally invoke the callback
410
409
  this.on('option:' + oname, function(val) {
411
410
  // coercion
412
- if (null !== val && fn) val = fn(val, undefined === self[name]
413
- ? defaultValue
414
- : self[name]);
411
+ if (val !== null && fn) {
412
+ val = fn(val, self[name] === undefined ? defaultValue : self[name]);
413
+ }
415
414
 
416
415
  // unassigned or bool
417
- if ('boolean' == typeof self[name] || 'undefined' == typeof self[name]) {
416
+ if (typeof self[name] === 'boolean' || typeof self[name] === 'undefined') {
418
417
  // if no value, bool true, and we have a default, then use it!
419
- if (null == val) {
418
+ if (val == null) {
420
419
  self[name] = option.bool
421
420
  ? defaultValue || true
422
421
  : false;
423
422
  } else {
424
423
  self[name] = val;
425
424
  }
426
- } else if (null !== val) {
425
+ } else if (val !== null) {
427
426
  // reassign
428
427
  self[name] = val;
429
428
  }
@@ -440,8 +439,8 @@ Command.prototype.option = function(flags, description, fn, defaultValue) {
440
439
  * @api public
441
440
  */
442
441
  Command.prototype.allowUnknownOption = function(arg) {
443
- this._allowUnknownOption = arguments.length === 0 || arg;
444
- return this;
442
+ this._allowUnknownOption = arguments.length === 0 || arg;
443
+ return this;
445
444
  };
446
445
 
447
446
  /**
@@ -485,7 +484,7 @@ Command.prototype.parse = function(argv) {
485
484
  })[0];
486
485
  }
487
486
 
488
- if (this._execs[name] && typeof this._execs[name] != "function") {
487
+ if (this._execs[name] && typeof this._execs[name] !== 'function') {
489
488
  return this.executeSubCommand(argv, args, parsed.unknown);
490
489
  } else if (aliasCommand) {
491
490
  // is alias of a subCommand
@@ -513,10 +512,10 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
513
512
  args = args.concat(unknown);
514
513
 
515
514
  if (!args.length) this.help();
516
- if ('help' == args[0] && 1 == args.length) this.help();
515
+ if (args[0] === 'help' && args.length === 1) this.help();
517
516
 
518
517
  // <cmd> --help
519
- if ('help' == args[0]) {
518
+ if (args[0] === 'help') {
520
519
  args[0] = args[1];
521
520
  args[1] = '--help';
522
521
  }
@@ -526,15 +525,14 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
526
525
  // name of the subcommand, link `pm-install`
527
526
  var bin = basename(f, '.js') + '-' + args[0];
528
527
 
529
-
530
528
  // In case of globally installed, get the base dir where executable
531
529
  // subcommand file should be located at
532
- var baseDir
533
- , link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
530
+ var baseDir,
531
+ link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
534
532
 
535
533
  // when symbolink is relative path
536
534
  if (link !== f && link.charAt(0) !== '/') {
537
- link = path.join(dirname(f), link)
535
+ link = path.join(dirname(f), link);
538
536
  }
539
537
  baseDir = dirname(link);
540
538
 
@@ -565,22 +563,22 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
565
563
  }
566
564
  } else {
567
565
  args.unshift(bin);
568
- proc = spawn(process.execPath, args, { stdio: 'inherit'});
566
+ proc = spawn(process.execPath, args, { stdio: 'inherit' });
569
567
  }
570
568
 
571
569
  var signals = ['SIGUSR1', 'SIGUSR2', 'SIGTERM', 'SIGINT', 'SIGHUP'];
572
570
  signals.forEach(function(signal) {
573
- process.on(signal, function(){
574
- if ((proc.killed === false) && (proc.exitCode === null)){
571
+ process.on(signal, function() {
572
+ if (proc.killed === false && proc.exitCode === null) {
575
573
  proc.kill(signal);
576
574
  }
577
575
  });
578
576
  });
579
577
  proc.on('close', process.exit.bind(process));
580
578
  proc.on('error', function(err) {
581
- if (err.code == "ENOENT") {
579
+ if (err.code === 'ENOENT') {
582
580
  console.error('\n %s(1) does not exist, try --help\n', bin);
583
- } else if (err.code == "EACCES") {
581
+ } else if (err.code === 'EACCES') {
584
582
  console.error('\n %s(1) not executable. try chmod or run with root\n', bin);
585
583
  }
586
584
  process.exit(1);
@@ -601,15 +599,15 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
601
599
  */
602
600
 
603
601
  Command.prototype.normalize = function(args) {
604
- var ret = []
605
- , arg
606
- , lastOpt
607
- , index;
602
+ var ret = [],
603
+ arg,
604
+ lastOpt,
605
+ index;
608
606
 
609
607
  for (var i = 0, len = args.length; i < len; ++i) {
610
608
  arg = args[i];
611
609
  if (i > 0) {
612
- lastOpt = this.optionFor(args[i-1]);
610
+ lastOpt = this.optionFor(args[i - 1]);
613
611
  }
614
612
 
615
613
  if (arg === '--') {
@@ -618,7 +616,7 @@ Command.prototype.normalize = function(args) {
618
616
  break;
619
617
  } else if (lastOpt && lastOpt.required) {
620
618
  ret.push(arg);
621
- } else if (arg.length > 1 && '-' == arg[0] && '-' != arg[1]) {
619
+ } else if (arg.length > 1 && arg[0] === '-' && arg[1] !== '-') {
622
620
  arg.slice(1).split('').forEach(function(c) {
623
621
  ret.push('-' + c);
624
622
  });
@@ -693,11 +691,11 @@ Command.prototype.optionFor = function(arg) {
693
691
  */
694
692
 
695
693
  Command.prototype.parseOptions = function(argv) {
696
- var args = []
697
- , len = argv.length
698
- , literal
699
- , option
700
- , arg;
694
+ var args = [],
695
+ len = argv.length,
696
+ literal,
697
+ option,
698
+ arg;
701
699
 
702
700
  var unknownOptions = [];
703
701
 
@@ -711,7 +709,7 @@ Command.prototype.parseOptions = function(argv) {
711
709
  continue;
712
710
  }
713
711
 
714
- if ('--' == arg) {
712
+ if (arg === '--') {
715
713
  literal = true;
716
714
  continue;
717
715
  }
@@ -724,12 +722,12 @@ Command.prototype.parseOptions = function(argv) {
724
722
  // requires arg
725
723
  if (option.required) {
726
724
  arg = argv[++i];
727
- if (null == arg) return this.optionMissingArgument(option);
725
+ if (arg == null) return this.optionMissingArgument(option);
728
726
  this.emit('option:' + option.name(), arg);
729
727
  // optional arg
730
728
  } else if (option.optional) {
731
- arg = argv[i+1];
732
- if (null == arg || ('-' == arg[0] && '-' != arg)) {
729
+ arg = argv[i + 1];
730
+ if (arg == null || (arg[0] === '-' && arg !== '-')) {
733
731
  arg = null;
734
732
  } else {
735
733
  ++i;
@@ -743,13 +741,13 @@ Command.prototype.parseOptions = function(argv) {
743
741
  }
744
742
 
745
743
  // looks like an option
746
- if (arg.length > 1 && '-' == arg[0]) {
744
+ if (arg.length > 1 && arg[0] === '-') {
747
745
  unknownOptions.push(arg);
748
746
 
749
747
  // If the next argument looks like it might be
750
748
  // an argument for this option, we pass it on.
751
749
  // If it isn't, then it'll simply be ignored
752
- if (argv[i+1] && '-' != argv[i+1][0]) {
750
+ if ((i + 1) < argv.length && argv[i + 1][0] !== '-') {
753
751
  unknownOptions.push(argv[++i]);
754
752
  }
755
753
  continue;
@@ -769,12 +767,12 @@ Command.prototype.parseOptions = function(argv) {
769
767
  * @api public
770
768
  */
771
769
  Command.prototype.opts = function() {
772
- var result = {}
773
- , len = this.options.length;
770
+ var result = {},
771
+ len = this.options.length;
774
772
 
775
- for (var i = 0 ; i < len; i++) {
773
+ for (var i = 0; i < len; i++) {
776
774
  var key = this.options[i].attributeName();
777
- result[key] = key === 'version' ? this._version : this[key];
775
+ result[key] = key === this._versionOptionName ? this._version : this[key];
778
776
  }
779
777
  return result;
780
778
  };
@@ -854,11 +852,13 @@ Command.prototype.variadicArgNotLast = function(name) {
854
852
  */
855
853
 
856
854
  Command.prototype.version = function(str, flags) {
857
- if (0 == arguments.length) return this._version;
855
+ if (arguments.length === 0) return this._version;
858
856
  this._version = str;
859
857
  flags = flags || '-V, --version';
860
- this.option(flags, 'output the version number');
861
- this.on('option:version', function() {
858
+ var versionOption = new Option(flags, 'output the version number');
859
+ this._versionOptionName = versionOption.long.substr(2) || 'version';
860
+ this.options.push(versionOption);
861
+ this.on('option:' + this._versionOptionName, function() {
862
862
  process.stdout.write(str + '\n');
863
863
  process.exit(0);
864
864
  });
@@ -874,7 +874,7 @@ Command.prototype.version = function(str, flags) {
874
874
  */
875
875
 
876
876
  Command.prototype.description = function(str) {
877
- if (0 === arguments.length) return this._description;
877
+ if (arguments.length === 0) return this._description;
878
878
  this._description = str;
879
879
  return this;
880
880
  };
@@ -889,8 +889,8 @@ Command.prototype.description = function(str) {
889
889
 
890
890
  Command.prototype.alias = function(alias) {
891
891
  var command = this;
892
- if(this.commands.length !== 0) {
893
- command = this.commands[this.commands.length - 1]
892
+ if (this.commands.length !== 0) {
893
+ command = this.commands[this.commands.length - 1];
894
894
  }
895
895
 
896
896
  if (arguments.length === 0) return command._alias;
@@ -914,11 +914,11 @@ Command.prototype.usage = function(str) {
914
914
  return humanReadableArgName(arg);
915
915
  });
916
916
 
917
- var usage = '[options]'
918
- + (this.commands.length ? ' [command]' : '')
919
- + (this._args.length ? ' ' + args.join(' ') : '');
917
+ var usage = '[options]' +
918
+ (this.commands.length ? ' [command]' : '') +
919
+ (this._args.length ? ' ' + args.join(' ') : '');
920
920
 
921
- if (0 == arguments.length) return this._usage || usage;
921
+ if (arguments.length === 0) return this._usage || usage;
922
922
  this._usage = str;
923
923
 
924
924
  return this;
@@ -933,7 +933,7 @@ Command.prototype.usage = function(str) {
933
933
  */
934
934
 
935
935
  Command.prototype.name = function(str) {
936
- if (0 === arguments.length) return this._name;
936
+ if (arguments.length === 0) return this._name;
937
937
  this._name = str;
938
938
  return this;
939
939
  };
@@ -963,8 +963,8 @@ Command.prototype.optionHelp = function() {
963
963
 
964
964
  // Append the help information
965
965
  return this.options.map(function(option) {
966
- return pad(option.flags, width) + ' ' + option.description
967
- + (option.defaultValue !== undefined ? ' (default: ' + option.defaultValue + ')' : '');
966
+ return pad(option.flags, width) + ' ' + option.description +
967
+ ((option.bool && option.defaultValue !== undefined) ? ' (default: ' + option.defaultValue + ')' : '');
968
968
  }).concat([pad('-h, --help', width) + ' ' + 'output usage information'])
969
969
  .join('\n');
970
970
  };
@@ -987,11 +987,11 @@ Command.prototype.commandHelp = function() {
987
987
  }).join(' ');
988
988
 
989
989
  return [
990
- cmd._name
991
- + (cmd._alias ? '|' + cmd._alias : '')
992
- + (cmd.options.length ? ' [options]' : '')
993
- + ' ' + args
994
- , cmd._description
990
+ cmd._name +
991
+ (cmd._alias ? '|' + cmd._alias : '') +
992
+ (cmd.options.length ? ' [options]' : '') +
993
+ (args ? ' ' + args : ''),
994
+ cmd._description
995
995
  ];
996
996
  });
997
997
 
@@ -1000,14 +1000,14 @@ Command.prototype.commandHelp = function() {
1000
1000
  }, 0);
1001
1001
 
1002
1002
  return [
1003
- ''
1004
- , ' Commands:'
1005
- , ''
1006
- , commands.map(function(cmd) {
1003
+ '',
1004
+ ' Commands:',
1005
+ '',
1006
+ commands.map(function(cmd) {
1007
1007
  var desc = cmd[1] ? ' ' + cmd[1] : '';
1008
- return pad(cmd[0], width) + desc;
1009
- }).join('\n').replace(/^/gm, ' ')
1010
- , ''
1008
+ return (desc ? pad(cmd[0], width) : cmd[0]) + desc;
1009
+ }).join('\n').replace(/^/gm, ' '),
1010
+ ''
1011
1011
  ].join('\n');
1012
1012
  };
1013
1013
 
@@ -1022,8 +1022,8 @@ Command.prototype.helpInformation = function() {
1022
1022
  var desc = [];
1023
1023
  if (this._description) {
1024
1024
  desc = [
1025
- ' ' + this._description
1026
- , ''
1025
+ ' ' + this._description,
1026
+ ''
1027
1027
  ];
1028
1028
  }
1029
1029
 
@@ -1032,9 +1032,9 @@ Command.prototype.helpInformation = function() {
1032
1032
  cmdName = cmdName + '|' + this._alias;
1033
1033
  }
1034
1034
  var usage = [
1035
+ '',
1036
+ ' Usage: ' + cmdName + ' ' + this.usage(),
1035
1037
  ''
1036
- ,' Usage: ' + cmdName + ' ' + this.usage()
1037
- , ''
1038
1038
  ];
1039
1039
 
1040
1040
  var cmds = [];
@@ -1042,11 +1042,11 @@ Command.prototype.helpInformation = function() {
1042
1042
  if (commandHelp) cmds = [commandHelp];
1043
1043
 
1044
1044
  var options = [
1045
+ '',
1046
+ ' Options:',
1047
+ '',
1048
+ '' + this.optionHelp().replace(/^/gm, ' '),
1045
1049
  ''
1046
- , ' Options:'
1047
- , ''
1048
- , '' + this.optionHelp().replace(/^/gm, ' ')
1049
- , ''
1050
1050
  ];
1051
1051
 
1052
1052
  return usage
@@ -1066,7 +1066,7 @@ Command.prototype.outputHelp = function(cb) {
1066
1066
  if (!cb) {
1067
1067
  cb = function(passthru) {
1068
1068
  return passthru;
1069
- }
1069
+ };
1070
1070
  }
1071
1071
  process.stdout.write(cb(this.helpInformation()));
1072
1072
  this.emit('--help');
@@ -1122,7 +1122,7 @@ function pad(str, width) {
1122
1122
  function outputHelpIfNecessary(cmd, options) {
1123
1123
  options = options || [];
1124
1124
  for (var i = 0; i < options.length; i++) {
1125
- if (options[i] == '--help' || options[i] == '-h') {
1125
+ if (options[i] === '--help' || options[i] === '-h') {
1126
1126
  cmd.outputHelp();
1127
1127
  process.exit(0);
1128
1128
  }
@@ -1142,7 +1142,7 @@ function humanReadableArgName(arg) {
1142
1142
 
1143
1143
  return arg.required
1144
1144
  ? '<' + nameOutput + '>'
1145
- : '[' + nameOutput + ']'
1145
+ : '[' + nameOutput + ']';
1146
1146
  }
1147
1147
 
1148
1148
  // for versions before node v0.8 when there weren't `fs.existsSync`
@@ -1155,4 +1155,3 @@ function exists(file) {
1155
1155
  return false;
1156
1156
  }
1157
1157
  }
1158
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commander",
3
- "version": "2.12.1",
3
+ "version": "2.14.1",
4
4
  "description": "the complete solution for node.js command-line programs",
5
5
  "keywords": [
6
6
  "commander",
@@ -15,19 +15,23 @@
15
15
  "url": "https://github.com/tj/commander.js.git"
16
16
  },
17
17
  "scripts": {
18
+ "lint": "eslint index.js",
18
19
  "test": "make test && npm run test-typings",
19
20
  "test-typings": "node_modules/typescript/bin/tsc -p tsconfig.json"
20
21
  },
21
22
  "main": "index",
22
23
  "files": [
23
- "index.js"
24
+ "index.js",
25
+ "typings/index.d.ts"
24
26
  ],
25
27
  "dependencies": {},
26
28
  "devDependencies": {
27
- "@types/node": "^7.0.48",
29
+ "@types/node": "^7.0.52",
30
+ "eslint": "^3.19.0",
28
31
  "should": "^11.2.1",
29
32
  "sinon": "^2.4.1",
30
- "typescript": "^2.6.1"
33
+ "standard": "^10.0.3",
34
+ "typescript": "^2.7.1"
31
35
  },
32
36
  "typings": "typings/index.d.ts"
33
37
  }
@@ -0,0 +1,309 @@
1
+ // Type definitions for commander 2.11
2
+ // Project: https://github.com/visionmedia/commander.js
3
+ // Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
4
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
+
6
+ declare namespace local {
7
+
8
+ class Option {
9
+ flags: string;
10
+ required: boolean;
11
+ optional: boolean;
12
+ bool: boolean;
13
+ short?: string;
14
+ long: string;
15
+ description: string;
16
+
17
+ /**
18
+ * Initialize a new `Option` with the given `flags` and `description`.
19
+ *
20
+ * @param {string} flags
21
+ * @param {string} [description]
22
+ */
23
+ constructor(flags: string, description?: string);
24
+ }
25
+
26
+ class Command extends NodeJS.EventEmitter {
27
+ [key: string]: any;
28
+
29
+ args: string[];
30
+
31
+ /**
32
+ * Initialize a new `Command`.
33
+ *
34
+ * @param {string} [name]
35
+ */
36
+ constructor(name?: string);
37
+
38
+ /**
39
+ * Set the program version to `str`.
40
+ *
41
+ * This method auto-registers the "-V, --version" flag
42
+ * which will print the version number when passed.
43
+ *
44
+ * @param {string} str
45
+ * @param {string} [flags]
46
+ * @returns {Command} for chaining
47
+ */
48
+ version(str: string, flags?: string): Command;
49
+
50
+ /**
51
+ * Add command `name`.
52
+ *
53
+ * The `.action()` callback is invoked when the
54
+ * command `name` is specified via __ARGV__,
55
+ * and the remaining arguments are applied to the
56
+ * function for access.
57
+ *
58
+ * When the `name` is "*" an un-matched command
59
+ * will be passed as the first arg, followed by
60
+ * the rest of __ARGV__ remaining.
61
+ *
62
+ * @example
63
+ * program
64
+ * .version('0.0.1')
65
+ * .option('-C, --chdir <path>', 'change the working directory')
66
+ * .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')
67
+ * .option('-T, --no-tests', 'ignore test hook')
68
+ *
69
+ * program
70
+ * .command('setup')
71
+ * .description('run remote setup commands')
72
+ * .action(function() {
73
+ * console.log('setup');
74
+ * });
75
+ *
76
+ * program
77
+ * .command('exec <cmd>')
78
+ * .description('run the given remote command')
79
+ * .action(function(cmd) {
80
+ * console.log('exec "%s"', cmd);
81
+ * });
82
+ *
83
+ * program
84
+ * .command('teardown <dir> [otherDirs...]')
85
+ * .description('run teardown commands')
86
+ * .action(function(dir, otherDirs) {
87
+ * console.log('dir "%s"', dir);
88
+ * if (otherDirs) {
89
+ * otherDirs.forEach(function (oDir) {
90
+ * console.log('dir "%s"', oDir);
91
+ * });
92
+ * }
93
+ * });
94
+ *
95
+ * program
96
+ * .command('*')
97
+ * .description('deploy the given env')
98
+ * .action(function(env) {
99
+ * console.log('deploying "%s"', env);
100
+ * });
101
+ *
102
+ * program.parse(process.argv);
103
+ *
104
+ * @param {string} name
105
+ * @param {string} [desc] for git-style sub-commands
106
+ * @param {CommandOptions} [opts] command options
107
+ * @returns {Command} the new command
108
+ */
109
+ command(name: string, desc?: string, opts?: commander.CommandOptions): Command;
110
+
111
+ /**
112
+ * Define argument syntax for the top-level command.
113
+ *
114
+ * @param {string} desc
115
+ * @returns {Command} for chaining
116
+ */
117
+ arguments(desc: string): Command;
118
+
119
+ /**
120
+ * Parse expected `args`.
121
+ *
122
+ * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.
123
+ *
124
+ * @param {string[]} args
125
+ * @returns {Command} for chaining
126
+ */
127
+ parseExpectedArgs(args: string[]): Command;
128
+
129
+ /**
130
+ * Register callback `fn` for the command.
131
+ *
132
+ * @example
133
+ * program
134
+ * .command('help')
135
+ * .description('display verbose help')
136
+ * .action(function() {
137
+ * // output help here
138
+ * });
139
+ *
140
+ * @param {(...args: any[]) => void} fn
141
+ * @returns {Command} for chaining
142
+ */
143
+ action(fn: (...args: any[]) => void): Command;
144
+
145
+ /**
146
+ * Define option with `flags`, `description` and optional
147
+ * coercion `fn`.
148
+ *
149
+ * The `flags` string should contain both the short and long flags,
150
+ * separated by comma, a pipe or space. The following are all valid
151
+ * all will output this way when `--help` is used.
152
+ *
153
+ * "-p, --pepper"
154
+ * "-p|--pepper"
155
+ * "-p --pepper"
156
+ *
157
+ * @example
158
+ * // simple boolean defaulting to false
159
+ * program.option('-p, --pepper', 'add pepper');
160
+ *
161
+ * --pepper
162
+ * program.pepper
163
+ * // => Boolean
164
+ *
165
+ * // simple boolean defaulting to true
166
+ * program.option('-C, --no-cheese', 'remove cheese');
167
+ *
168
+ * program.cheese
169
+ * // => true
170
+ *
171
+ * --no-cheese
172
+ * program.cheese
173
+ * // => false
174
+ *
175
+ * // required argument
176
+ * program.option('-C, --chdir <path>', 'change the working directory');
177
+ *
178
+ * --chdir /tmp
179
+ * program.chdir
180
+ * // => "/tmp"
181
+ *
182
+ * // optional argument
183
+ * program.option('-c, --cheese [type]', 'add cheese [marble]');
184
+ *
185
+ * @param {string} flags
186
+ * @param {string} [description]
187
+ * @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default
188
+ * @param {*} [defaultValue]
189
+ * @returns {Command} for chaining
190
+ */
191
+ option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command;
192
+ option(flags: string, description?: string, defaultValue?: any): Command;
193
+
194
+ /**
195
+ * Allow unknown options on the command line.
196
+ *
197
+ * @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options.
198
+ * @returns {Command} for chaining
199
+ */
200
+ allowUnknownOption(arg?: boolean): Command;
201
+
202
+ /**
203
+ * Parse `argv`, settings options and invoking commands when defined.
204
+ *
205
+ * @param {string[]} argv
206
+ * @returns {Command} for chaining
207
+ */
208
+ parse(argv: string[]): Command;
209
+
210
+ /**
211
+ * Parse options from `argv` returning `argv` void of these options.
212
+ *
213
+ * @param {string[]} argv
214
+ * @returns {ParseOptionsResult}
215
+ */
216
+ parseOptions(argv: string[]): commander.ParseOptionsResult;
217
+
218
+ /**
219
+ * Return an object containing options as key-value pairs
220
+ *
221
+ * @returns {{[key: string]: string}}
222
+ */
223
+ opts(): { [key: string]: string };
224
+
225
+ /**
226
+ * Set the description to `str`.
227
+ *
228
+ * @param {string} str
229
+ * @return {(Command | string)}
230
+ */
231
+ description(str: string): Command;
232
+ description(): string;
233
+
234
+ /**
235
+ * Set an alias for the command.
236
+ *
237
+ * @param {string} alias
238
+ * @return {(Command | string)}
239
+ */
240
+ alias(alias: string): Command;
241
+ alias(): string;
242
+
243
+ /**
244
+ * Set or get the command usage.
245
+ *
246
+ * @param {string} str
247
+ * @return {(Command | string)}
248
+ */
249
+ usage(str: string): Command;
250
+ usage(): string;
251
+
252
+ /**
253
+ * Set the name of the command.
254
+ *
255
+ * @param {string} str
256
+ * @return {Command}
257
+ */
258
+ name(str: string): Command;
259
+
260
+ /**
261
+ * Get the name of the command.
262
+ *
263
+ * @return {string}
264
+ */
265
+ name(): string;
266
+
267
+ /**
268
+ * Output help information for this command.
269
+ *
270
+ * @param {(str: string) => string} [cb]
271
+ */
272
+ outputHelp(cb?: (str: string) => string): void;
273
+
274
+ /** Output help information and exit.
275
+ *
276
+ * @param {(str: string) => string} [cb]
277
+ */
278
+ help(cb?: (str: string) => string): void;
279
+ }
280
+
281
+ }
282
+
283
+ declare namespace commander {
284
+
285
+ type Command = local.Command
286
+
287
+ type Option = local.Option
288
+
289
+ interface CommandOptions {
290
+ noHelp?: boolean;
291
+ isDefault?: boolean;
292
+ }
293
+
294
+ interface ParseOptionsResult {
295
+ args: string[];
296
+ unknown: string[];
297
+ }
298
+
299
+ interface CommanderStatic extends Command {
300
+ Command: typeof local.Command;
301
+ Option: typeof local.Option;
302
+ CommandOptions: CommandOptions;
303
+ ParseOptionsResult: ParseOptionsResult;
304
+ }
305
+
306
+ }
307
+
308
+ declare const commander: commander.CommanderStatic;
309
+ export = commander;