@@ -7,6 +7,8 @@ const spawn = require('child_process').spawn;
7
7
const path = require ( 'path' ) ;
8
8
const fs = require ( 'fs' ) ;
9
9
10
+ // @ts -check
11
+
10
12
class Option {
11
13
/**
12
14
* Initialize a new `Option` with the given `flags` and `description`.
@@ -22,10 +24,11 @@ class Option {
22
24
this . optional = flags . indexOf ( '[' ) >= 0 ; // A value is optional when the option is specified.
23
25
this . mandatory = false ; // The option must have a value after parsing, which usually means it must be specified on command line.
24
26
this . negate = flags . indexOf ( '-no-' ) !== - 1 ;
25
- flags = flags . split ( / [ , | ] + / ) ;
26
- if ( flags . length > 1 && ! / ^ [ [ < ] / . test ( flags [ 1 ] ) ) this . short = flags . shift ( ) ;
27
- this . long = flags . shift ( ) ;
27
+ const flagParts = flags . split ( / [ , | ] + / ) ;
28
+ if ( flagParts . length > 1 && ! / ^ [ [ < ] / . test ( flagParts [ 1 ] ) ) this . short = flagParts . shift ( ) ;
29
+ this . long = flagParts . shift ( ) ;
28
30
this . description = description || '' ;
31
+ this . defaultValue = undefined ;
29
32
}
30
33
31
34
/**
@@ -83,6 +86,7 @@ class CommanderError extends Error {
83
86
this . name = this . constructor . name ;
84
87
this . code = code ;
85
88
this . exitCode = exitCode ;
89
+ this . nestedError = undefined ;
86
90
}
87
91
}
88
92
@@ -98,6 +102,7 @@ class Command extends EventEmitter {
98
102
super ( ) ;
99
103
this . commands = [ ] ;
100
104
this . options = [ ] ;
105
+ this . parent = null ;
101
106
this . _allowUnknownOption = false ;
102
107
this . _args = [ ] ;
103
108
this . rawArgs = null ;
@@ -112,6 +117,7 @@ class Command extends EventEmitter {
112
117
this . _executableFile = null ; // custom name for executable
113
118
this . _defaultCommandName = null ;
114
119
this . _exitCallback = null ;
120
+ this . _alias = null ;
115
121
116
122
this . _noHelp = false ;
117
123
this . _helpFlags = '-h, --help' ;
@@ -634,7 +640,7 @@ class Command extends EventEmitter {
634
640
*
635
641
* @param {string[] } [argv] - optional, defaults to process.argv
636
642
* @param {Object } [parseOptions] - optionally specify style of options with from: node/user/electron
637
- * @param {string } parseOptions.from - where the args are from: 'node', 'user', 'electron'
643
+ * @param {string } [ parseOptions.from] - where the args are from: 'node', 'user', 'electron'
638
644
* @return {Command } for chaining
639
645
* @api public
640
646
*/
@@ -648,6 +654,7 @@ class Command extends EventEmitter {
648
654
// Default to using process.argv
649
655
if ( argv === undefined ) {
650
656
argv = process . argv ;
657
+ // @ts -ignore
651
658
if ( process . versions && process . versions . electron ) {
652
659
parseOptions . from = 'electron' ;
653
660
}
@@ -663,6 +670,7 @@ class Command extends EventEmitter {
663
670
userArgs = argv . slice ( 2 ) ;
664
671
break ;
665
672
case 'electron' :
673
+ // @ts -ignore
666
674
if ( process . defaultApp ) {
667
675
this . _scriptPath = argv [ 1 ] ;
668
676
userArgs = argv . slice ( 2 ) ;
@@ -780,6 +788,7 @@ class Command extends EventEmitter {
780
788
781
789
const signals = [ 'SIGUSR1' , 'SIGUSR2' , 'SIGTERM' , 'SIGINT' , 'SIGHUP' ] ;
782
790
signals . forEach ( ( signal ) => {
791
+ // @ts -ignore
783
792
process . on ( signal , ( ) => {
784
793
if ( proc . killed === false && proc . exitCode === null ) {
785
794
proc . kill ( signal ) ;
@@ -798,11 +807,13 @@ class Command extends EventEmitter {
798
807
} ) ;
799
808
}
800
809
proc . on ( 'error' , ( err ) => {
810
+ // @ts -ignore
801
811
if ( err . code === 'ENOENT' ) {
802
812
const executableMissing = `'${ bin } ' does not exist
803
813
- if '${ subcommand . _name } ' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
804
814
- if the default executable name is not suitable, use the executableFile option to supply a custom name` ;
805
815
throw new Error ( executableMissing ) ;
816
+ // @ts -ignore
806
817
} else if ( err . code === 'EACCES' ) {
807
818
throw new Error ( `'${ bin } ' not executable` ) ;
808
819
}
@@ -1119,7 +1130,6 @@ class Command extends EventEmitter {
1119
1130
/**
1120
1131
* Unknown command.
1121
1132
*
1122
- * @param {string } flag
1123
1133
* @api private
1124
1134
*/
1125
1135
@@ -1145,7 +1155,7 @@ class Command extends EventEmitter {
1145
1155
* @param {string } str
1146
1156
* @param {string } [flags]
1147
1157
* @param {string } [description]
1148
- * @return {Command } for chaining
1158
+ * @return {Command | string } this for chaining
1149
1159
* @api public
1150
1160
*/
1151
1161
0 commit comments