@@ -38,9 +38,7 @@ class Command extends EventEmitter {
38
38
*
39
39
* @type {Command | null }
40
40
*/
41
- this . currentParent = null ;
42
- /** @type {Command | null } */
43
- this . parent = null ; // last added parent command (legacy)
41
+ this . parent = null ;
44
42
this . _allowUnknownOption = false ;
45
43
this . _allowExcessArguments = true ;
46
44
/** @type {Argument[] } */
@@ -171,7 +169,7 @@ class Command extends EventEmitter {
171
169
if ( args ) cmd . arguments ( args ) ;
172
170
this . commands . push ( cmd ) ;
173
171
cmd . parents . push ( this ) ;
174
- cmd . currentParent = cmd . parent = this ;
172
+ cmd . parent = this ;
175
173
cmd . copyInheritedSettings ( this ) ;
176
174
177
175
if ( desc ) return this ;
@@ -289,7 +287,7 @@ class Command extends EventEmitter {
289
287
290
288
this . commands . push ( cmd ) ;
291
289
cmd . parents . push ( this ) ;
292
- cmd . currentParent = cmd . parent = this ;
290
+ cmd . parent = this ;
293
291
cmd . _checkForBrokenPassThrough ( ) ;
294
292
295
293
return this ;
@@ -1306,8 +1304,8 @@ Call on top-level command instead`);
1306
1304
* @api private
1307
1305
*/
1308
1306
1309
- _parseCommand ( operands , unknown , currentParent ) {
1310
- this . currentParent = currentParent ?? null ;
1307
+ _parseCommand ( operands , unknown , parent ) {
1308
+ this . parent = parent ?? null ;
1311
1309
1312
1310
const parsed = this . parseOptions ( unknown ) ;
1313
1311
this . _parseOptionsEnv ( ) ; // after cli, so parseArg not called on both cli and env
@@ -1350,18 +1348,18 @@ Call on top-level command instead`);
1350
1348
let actionResult ;
1351
1349
actionResult = this . _chainOrCallHooks ( actionResult , 'preAction' ) ;
1352
1350
actionResult = this . _chainOrCall ( actionResult , ( ) => this . _actionHandler ( this . processedArgs ) ) ;
1353
- if ( currentParent ) {
1351
+ if ( parent ) {
1354
1352
actionResult = this . _chainOrCall ( actionResult , ( ) => {
1355
- currentParent . emit ( commandEvent , operands , unknown ) ; // legacy
1353
+ parent . emit ( commandEvent , operands , unknown ) ; // legacy
1356
1354
} ) ;
1357
1355
}
1358
1356
actionResult = this . _chainOrCallHooks ( actionResult , 'postAction' ) ;
1359
1357
return actionResult ;
1360
1358
}
1361
- if ( currentParent ?. listenerCount ( commandEvent ) ) {
1359
+ if ( parent ?. listenerCount ( commandEvent ) ) {
1362
1360
checkForUnknownOptions ( ) ;
1363
1361
this . _processArguments ( ) ;
1364
- currentParent . emit ( commandEvent , operands , unknown ) ; // legacy
1362
+ parent . emit ( commandEvent , operands , unknown ) ; // legacy
1365
1363
} else if ( operands . length ) {
1366
1364
if ( this . _findCommand ( '*' ) ) { // legacy default command
1367
1365
return this . _dispatchSubcommand ( '*' , operands , unknown ) ;
@@ -1417,7 +1415,7 @@ Call on top-level command instead`);
1417
1415
1418
1416
_checkForMissingMandatoryOptions ( ) {
1419
1417
// Walk up hierarchy so can call in subcommand after checking for displaying help.
1420
- for ( let cmd = this ; cmd ; cmd = cmd . currentParent ) {
1418
+ for ( let cmd = this ; cmd ; cmd = cmd . parent ) {
1421
1419
cmd . options . forEach ( ( anOption ) => {
1422
1420
if ( anOption . mandatory && ( cmd . getOptionValue ( anOption . attributeName ( ) ) === undefined ) ) {
1423
1421
cmd . missingMandatoryOptionValue ( anOption ) ;
@@ -1464,7 +1462,7 @@ Call on top-level command instead`);
1464
1462
*/
1465
1463
_checkForConflictingOptions ( ) {
1466
1464
// Walk up hierarchy so can call in subcommand after checking for displaying help.
1467
- for ( let cmd = this ; cmd ; cmd = cmd . currentParent ) {
1465
+ for ( let cmd = this ; cmd ; cmd = cmd . parent ) {
1468
1466
cmd . _checkForConflictingLocalOptions ( ) ;
1469
1467
}
1470
1468
}
@@ -1801,7 +1799,7 @@ Call on top-level command instead`);
1801
1799
. filter ( option => option . long )
1802
1800
. map ( option => option . long ) ;
1803
1801
candidateFlags = candidateFlags . concat ( moreFlags ) ;
1804
- command = command . currentParent ;
1802
+ command = command . parent ;
1805
1803
} while ( command && ! command . _enablePositionalOptions ) ;
1806
1804
suggestion = suggestSimilar ( flag , candidateFlags ) ;
1807
1805
}
@@ -1822,7 +1820,7 @@ Call on top-level command instead`);
1822
1820
1823
1821
const expected = this . _args . length ;
1824
1822
const s = ( expected === 1 ) ? '' : 's' ;
1825
- const forSubcommand = this . currentParent ? ` for '${ this . name ( ) } '` : '' ;
1823
+ const forSubcommand = this . parent ? ` for '${ this . name ( ) } '` : '' ;
1826
1824
const message = `error: too many arguments${ forSubcommand } . Expected ${ expected } argument${ s } but got ${ receivedArgs . length } .` ;
1827
1825
this . error ( message , { code : 'commander.excessArguments' } ) ;
1828
1826
}
@@ -2239,7 +2237,7 @@ function incrementNodeInspectorPort(args) {
2239
2237
2240
2238
function getCommandAndParents ( startCommand ) {
2241
2239
const result = [ ] ;
2242
- for ( let command = startCommand ; command ; command = command . currentParent ) {
2240
+ for ( let command = startCommand ; command ; command = command . parent ) {
2243
2241
result . push ( command ) ;
2244
2242
}
2245
2243
return result ;
0 commit comments