@@ -582,7 +582,7 @@ class Command extends EventEmitter {
582
582
* @api public
583
583
*/
584
584
allowUnknownOption ( arg ) {
585
- this . _allowUnknownOption = arguments . length === 0 || arg ;
585
+ this . _allowUnknownOption = ( arg === undefined ) || arg ;
586
586
return this ;
587
587
} ;
588
588
@@ -1182,7 +1182,7 @@ class Command extends EventEmitter {
1182
1182
*/
1183
1183
1184
1184
version ( str , flags , description ) {
1185
- if ( arguments . length === 0 ) return this . _version ;
1185
+ if ( str === undefined ) return this . _version ;
1186
1186
this . _version = str ;
1187
1187
flags = flags || '-V, --version' ;
1188
1188
description = description || 'output the version number' ;
@@ -1206,7 +1206,7 @@ class Command extends EventEmitter {
1206
1206
*/
1207
1207
1208
1208
description ( str , argsDescription ) {
1209
- if ( arguments . length === 0 ) return this . _description ;
1209
+ if ( str === undefined && argsDescription === undefined ) return this . _description ;
1210
1210
this . _description = str ;
1211
1211
this . _argsDescription = argsDescription ;
1212
1212
return this ;
@@ -1221,13 +1221,14 @@ class Command extends EventEmitter {
1221
1221
*/
1222
1222
1223
1223
alias ( alias ) {
1224
+ if ( alias === undefined ) return this . _alias ;
1225
+
1224
1226
let command = this ;
1225
- if ( this . commands . length !== 0 ) {
1227
+ if ( this . commands . length !== 0 && this . commands [ this . commands . length - 1 ] . _executableHandler ) {
1228
+ // assume adding alias for last added executable subcommand, rather than this
1226
1229
command = this . commands [ this . commands . length - 1 ] ;
1227
1230
}
1228
1231
1229
- if ( arguments . length === 0 ) return command . _alias ;
1230
-
1231
1232
if ( alias === command . _name ) throw new Error ( 'Command alias can\'t be the same as its name' ) ;
1232
1233
1233
1234
command . _alias = alias ;
@@ -1243,17 +1244,18 @@ class Command extends EventEmitter {
1243
1244
*/
1244
1245
1245
1246
usage ( str ) {
1246
- const args = this . _args . map ( ( arg ) => {
1247
- return humanReadableArgName ( arg ) ;
1248
- } ) ;
1247
+ if ( str === undefined ) {
1248
+ if ( this . _usage ) return this . _usage ;
1249
1249
1250
- const usage = '[options]' +
1251
- ( this . commands . length ? ' [command]' : '' ) +
1252
- ( this . _args . length ? ' ' + args . join ( ' ' ) : '' ) ;
1250
+ const args = this . _args . map ( ( arg ) => {
1251
+ return humanReadableArgName ( arg ) ;
1252
+ } ) ;
1253
+ return '[options]' +
1254
+ ( this . commands . length ? ' [command]' : '' ) +
1255
+ ( this . _args . length ? ' ' + args . join ( ' ' ) : '' ) ;
1256
+ }
1253
1257
1254
- if ( arguments . length === 0 ) return this . _usage || usage ;
1255
1258
this . _usage = str ;
1256
-
1257
1259
return this ;
1258
1260
} ;
1259
1261
@@ -1266,7 +1268,7 @@ class Command extends EventEmitter {
1266
1268
*/
1267
1269
1268
1270
name ( str ) {
1269
- if ( arguments . length === 0 ) return this . _name ;
1271
+ if ( str === undefined ) return this . _name ;
1270
1272
this . _name = str ;
1271
1273
return this ;
1272
1274
} ;
0 commit comments