@@ -1036,8 +1036,11 @@ function Yargs (processArgs, cwd, parentRequire) {
10361036 argv [ helpOpt ] = true
10371037 }
10381038 }
1039+
10391040 const handlerKeys = command . getCommands ( )
1040- const skipDefaultCommand = argv [ helpOpt ] && ( handlerKeys . length > 1 || handlerKeys [ 0 ] !== '$0' )
1041+ const requestCompletions = completion . completionKey in argv
1042+ const skipRecommendation = argv [ helpOpt ] || requestCompletions
1043+ const skipDefaultCommand = skipRecommendation && ( handlerKeys . length > 1 || handlerKeys [ 0 ] !== '$0' )
10411044
10421045 if ( argv . _ . length ) {
10431046 if ( handlerKeys . length ) {
@@ -1064,13 +1067,13 @@ function Yargs (processArgs, cwd, parentRequire) {
10641067
10651068 // recommend a command if recommendCommands() has
10661069 // been enabled, and no commands were found to execute
1067- if ( recommendCommands && firstUnknownCommand && ! argv [ helpOpt ] ) {
1070+ if ( recommendCommands && firstUnknownCommand && ! skipRecommendation ) {
10681071 validation . recommendCommands ( firstUnknownCommand , handlerKeys )
10691072 }
10701073 }
10711074
10721075 // generate a completion script for adding to ~/.bashrc.
1073- if ( completionCommand && ~ argv . _ . indexOf ( completionCommand ) && ! argv [ completion . completionKey ] ) {
1076+ if ( completionCommand && ~ argv . _ . indexOf ( completionCommand ) && ! requestCompletions ) {
10741077 if ( exitProcess ) setBlocking ( true )
10751078 self . showCompletionScript ( )
10761079 self . exit ( 0 )
@@ -1082,7 +1085,7 @@ function Yargs (processArgs, cwd, parentRequire) {
10821085
10831086 // we must run completions first, a user might
10841087 // want to complete the --help or --version option.
1085- if ( completion . completionKey in argv ) {
1088+ if ( requestCompletions ) {
10861089 if ( exitProcess ) setBlocking ( true )
10871090
10881091 // we allow for asynchronous completions,
@@ -1130,7 +1133,7 @@ function Yargs (processArgs, cwd, parentRequire) {
11301133
11311134 // if we're executed via bash completion, don't
11321135 // bother with validation.
1133- if ( ! argv [ completion . completionKey ] ) {
1136+ if ( ! requestCompletions ) {
11341137 self . _runValidation ( argv , aliases , { } , parsed . error )
11351138 }
11361139 }
0 commit comments