@@ -1378,13 +1378,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
13781378
13791379 _checkForMissingMandatoryOptions ( ) {
13801380 // Walk up hierarchy so can call in subcommand after checking for displaying help.
1381- for ( let cmd = this ; cmd ; cmd = cmd . parent ) {
1381+ this . _getCommandAndAncestors ( ) . forEach ( ( cmd ) => {
13821382 cmd . options . forEach ( ( anOption ) => {
13831383 if ( anOption . mandatory && ( cmd . getOptionValue ( anOption . attributeName ( ) ) === undefined ) ) {
13841384 cmd . missingMandatoryOptionValue ( anOption ) ;
13851385 }
13861386 } ) ;
1387- }
1387+ } ) ;
13881388 }
13891389
13901390 /**
@@ -1425,9 +1425,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
14251425 */
14261426 _checkForConflictingOptions ( ) {
14271427 // Walk up hierarchy so can call in subcommand after checking for displaying help.
1428- for ( let cmd = this ; cmd ; cmd = cmd . parent ) {
1428+ this . _getCommandAndAncestors ( ) . forEach ( ( cmd ) => {
14291429 cmd . _checkForConflictingLocalOptions ( ) ;
1430- }
1430+ } ) ;
14311431 }
14321432
14331433 /**
@@ -1756,14 +1756,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
17561756 if ( flag . startsWith ( '--' ) && this . _showSuggestionAfterError ) {
17571757 // Looping to pick up the global options too
17581758 let candidateFlags = [ ] ;
1759- let command = this ;
1760- do {
1759+ for ( const command of this . _getCommandAndAncestors ( ) ) {
17611760 const moreFlags = command . createHelp ( ) . visibleOptions ( command )
17621761 . filter ( option => option . long )
17631762 . map ( option => option . long ) ;
17641763 candidateFlags = candidateFlags . concat ( moreFlags ) ;
1765- command = command . parent ;
1766- } while ( command && ! command . _enablePositionalOptions ) ;
1764+ if ( command . _enablePositionalOptions ) break ;
1765+ }
17671766 suggestion = suggestSimilar ( flag , candidateFlags ) ;
17681767 }
17691768
0 commit comments