commander 2.18.0 → 2.20.3

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,3 +1,33 @@
1
+ 2.20.3 / 2019-10-11
2
+ ==================
3
+
4
+ * Support Node.js 0.10 (Revert #1059)
5
+ * Ran "npm unpublish commander@2.20.2". There is no 2.20.2.
6
+
7
+ 2.20.1 / 2019-09-29
8
+ ==================
9
+
10
+ * Improve executable subcommand tracking
11
+ * Update dev dependencies
12
+
13
+ 2.20.0 / 2019-04-02
14
+ ==================
15
+
16
+ * fix: resolve symbolic links completely when hunting for subcommands (#935)
17
+ * Update index.d.ts (#930)
18
+ * Update Readme.md (#924)
19
+ * Remove --save option as it isn't required anymore (#918)
20
+ * Add link to the license file (#900)
21
+ * Added example of receiving args from options (#858)
22
+ * Added missing semicolon (#882)
23
+ * Add extension to .eslintrc (#876)
24
+
25
+ 2.19.0 / 2018-10-02
26
+ ==================
27
+
28
+ * Removed newline after Options and Commands headers (#864)
29
+ * Bugfix - Error output (#862)
30
+ * Fix to change default value to string (#856)
1
31
 
2
32
  2.18.0 / 2018-09-07
3
33
  ==================
package/Readme.md CHANGED
@@ -13,7 +13,7 @@
13
13
 
14
14
  ## Installation
15
15
 
16
- $ npm install commander --save
16
+ $ npm install commander
17
17
 
18
18
  ## Option parsing
19
19
 
@@ -65,6 +65,17 @@ if (program.sauce) console.log(' with sauce');
65
65
  else console.log(' without sauce');
66
66
  ```
67
67
 
68
+ To get string arguments from options you will need to use angle brackets <> for required inputs or square brackets [] for optional inputs.
69
+
70
+ e.g. ```.option('-m --myarg [myVar]', 'my super cool description')```
71
+
72
+ Then to access the input if it was passed in.
73
+
74
+ e.g. ```var myInput = program.myarg```
75
+
76
+ **NOTE**: If you pass a argument without using brackets the example above will return true and not the value passed in.
77
+
78
+
68
79
  ## Version option
69
80
 
70
81
  Calling the `version` implicitly adds the `-V` and `--version` options to the command.
@@ -254,7 +265,6 @@ Usage: pizza [options]
254
265
  An application for pizzas ordering
255
266
 
256
267
  Options:
257
-
258
268
  -h, --help output usage information
259
269
  -V, --version output the version number
260
270
  -p, --peppers Add peppers
@@ -294,7 +304,6 @@ program
294
304
  program.on('--help', function(){
295
305
  console.log('')
296
306
  console.log('Examples:');
297
- console.log('');
298
307
  console.log(' $ custom-help --help');
299
308
  console.log(' $ custom-help -h');
300
309
  });
@@ -310,7 +319,6 @@ Yields the following help output when `node script-name.js -h` or `node script-n
310
319
  Usage: custom-help [options]
311
320
 
312
321
  Options:
313
-
314
322
  -h, --help output usage information
315
323
  -V, --version output the version number
316
324
  -f, --foo enable some foo
@@ -318,7 +326,6 @@ Options:
318
326
  -B, --baz enable some baz
319
327
 
320
328
  Examples:
321
-
322
329
  $ custom-help --help
323
330
  $ custom-help -h
324
331
  ```
@@ -418,4 +425,4 @@ More Demos can be found in the [examples](https://github.com/tj/commander.js/tre
418
425
 
419
426
  ## License
420
427
 
421
- MIT
428
+ [MIT](https://github.com/tj/commander.js/blob/master/LICENSE)
package/index.js CHANGED
@@ -484,7 +484,7 @@ Command.prototype.parse = function(argv) {
484
484
  })[0];
485
485
  }
486
486
 
487
- if (this._execs[name] && typeof this._execs[name] !== 'function') {
487
+ if (this._execs[name] === true) {
488
488
  return this.executeSubCommand(argv, args, parsed.unknown);
489
489
  } else if (aliasCommand) {
490
490
  // is alias of a subCommand
@@ -527,14 +527,11 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
527
527
 
528
528
  // In case of globally installed, get the base dir where executable
529
529
  // subcommand file should be located at
530
- var baseDir,
531
- link = fs.lstatSync(f).isSymbolicLink() ? fs.readlinkSync(f) : f;
530
+ var baseDir;
532
531
 
533
- // when symbolink is relative path
534
- if (link !== f && link.charAt(0) !== '/') {
535
- link = path.join(dirname(f), link);
536
- }
537
- baseDir = dirname(link);
532
+ var resolvedLink = fs.realpathSync(f);
533
+
534
+ baseDir = dirname(resolvedLink);
538
535
 
539
536
  // prefer local `./<bin>` to bin in the $PATH
540
537
  var localBin = path.join(baseDir, bin);
@@ -580,9 +577,9 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
580
577
  proc.on('close', process.exit.bind(process));
581
578
  proc.on('error', function(err) {
582
579
  if (err.code === 'ENOENT') {
583
- console.error('%s(1) does not exist, try --help', bin);
580
+ console.error('error: %s(1) does not exist, try --help', bin);
584
581
  } else if (err.code === 'EACCES') {
585
- console.error('%s(1) not executable. try chmod or run with root', bin);
582
+ console.error('error: %s(1) not executable. try chmod or run with root', bin);
586
583
  }
587
584
  process.exit(1);
588
585
  });
@@ -664,7 +661,7 @@ Command.prototype.parseArgs = function(args, unknown) {
664
661
  this.unknownOption(unknown[0]);
665
662
  }
666
663
  if (this.commands.length === 0 &&
667
- this._args.filter(function(a) { return a.required }).length === 0) {
664
+ this._args.filter(function(a) { return a.required; }).length === 0) {
668
665
  this.emit('command:*');
669
666
  }
670
667
  }
@@ -792,9 +789,7 @@ Command.prototype.opts = function() {
792
789
  */
793
790
 
794
791
  Command.prototype.missingArgument = function(name) {
795
- console.error();
796
- console.error(" error: missing required argument `%s'", name);
797
- console.error();
792
+ console.error("error: missing required argument `%s'", name);
798
793
  process.exit(1);
799
794
  };
800
795
 
@@ -807,13 +802,11 @@ Command.prototype.missingArgument = function(name) {
807
802
  */
808
803
 
809
804
  Command.prototype.optionMissingArgument = function(option, flag) {
810
- console.error();
811
805
  if (flag) {
812
- console.error(" error: option `%s' argument missing, got `%s'", option.flags, flag);
806
+ console.error("error: option `%s' argument missing, got `%s'", option.flags, flag);
813
807
  } else {
814
- console.error(" error: option `%s' argument missing", option.flags);
808
+ console.error("error: option `%s' argument missing", option.flags);
815
809
  }
816
- console.error();
817
810
  process.exit(1);
818
811
  };
819
812
 
@@ -826,9 +819,7 @@ Command.prototype.optionMissingArgument = function(option, flag) {
826
819
 
827
820
  Command.prototype.unknownOption = function(flag) {
828
821
  if (this._allowUnknownOption) return;
829
- console.error();
830
- console.error(" error: unknown option `%s'", flag);
831
- console.error();
822
+ console.error("error: unknown option `%s'", flag);
832
823
  process.exit(1);
833
824
  };
834
825
 
@@ -840,9 +831,7 @@ Command.prototype.unknownOption = function(flag) {
840
831
  */
841
832
 
842
833
  Command.prototype.variadicArgNotLast = function(name) {
843
- console.error();
844
- console.error(" error: variadic arguments must be last `%s'", name);
845
- console.error();
834
+ console.error("error: variadic arguments must be last `%s'", name);
846
835
  process.exit(1);
847
836
  };
848
837
 
@@ -1053,7 +1042,7 @@ Command.prototype.optionHelp = function() {
1053
1042
  // Append the help information
1054
1043
  return this.options.map(function(option) {
1055
1044
  return pad(option.flags, width) + ' ' + option.description +
1056
- ((option.bool && option.defaultValue !== undefined) ? ' (default: ' + option.defaultValue + ')' : '');
1045
+ ((option.bool && option.defaultValue !== undefined) ? ' (default: ' + JSON.stringify(option.defaultValue) + ')' : '');
1057
1046
  }).concat([pad('-h, --help', width) + ' ' + 'output usage information'])
1058
1047
  .join('\n');
1059
1048
  };
@@ -1073,7 +1062,6 @@ Command.prototype.commandHelp = function() {
1073
1062
 
1074
1063
  return [
1075
1064
  'Commands:',
1076
- '',
1077
1065
  commands.map(function(cmd) {
1078
1066
  var desc = cmd[1] ? ' ' + cmd[1] : '';
1079
1067
  return (desc ? pad(cmd[0], width) : cmd[0]) + desc;
@@ -1124,7 +1112,6 @@ Command.prototype.helpInformation = function() {
1124
1112
 
1125
1113
  var options = [
1126
1114
  'Options:',
1127
- '',
1128
1115
  '' + this.optionHelp().replace(/^/gm, ' '),
1129
1116
  ''
1130
1117
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "commander",
3
- "version": "2.18.0",
3
+ "version": "2.20.3",
4
4
  "description": "the complete solution for node.js command-line programs",
5
5
  "keywords": [
6
6
  "commander",
@@ -26,13 +26,13 @@
26
26
  ],
27
27
  "dependencies": {},
28
28
  "devDependencies": {
29
- "@types/node": "^10.9.4",
30
- "eslint": "^5.5.0",
29
+ "@types/node": "^12.7.8",
30
+ "eslint": "^6.4.0",
31
31
  "should": "^13.2.3",
32
- "sinon": "^6.2.0",
33
- "standard": "^12.0.1",
34
- "ts-node": "^7.0.1",
35
- "typescript": "^2.9.2"
32
+ "sinon": "^7.5.0",
33
+ "standard": "^14.3.1",
34
+ "ts-node": "^8.4.1",
35
+ "typescript": "^3.6.3"
36
36
  },
37
37
  "typings": "typings/index.d.ts"
38
38
  }
@@ -226,9 +226,10 @@ declare namespace local {
226
226
  * Set the description to `str`.
227
227
  *
228
228
  * @param {string} str
229
+ * @param {{[argName: string]: string}} argsDescription
229
230
  * @return {(Command | string)}
230
231
  */
231
- description(str: string): Command;
232
+ description(str: string, argsDescription?: {[argName: string]: string}): Command;
232
233
  description(): string;
233
234
 
234
235
  /**