@@ -105,13 +105,13 @@ export class CommandsService implements ICommandsService {
105
105
return this . $helpService . showCommandLineHelp ( { commandName : this . beautifyCommandName ( commandName ) , commandArguments } ) ;
106
106
}
107
107
108
- private async executeCommandAction ( commandName : string , commandArguments : string [ ] , action : ( _commandName : string , _commandArguments : string [ ] ) => Promise < boolean > ) : Promise < boolean > {
108
+ private async executeCommandAction ( commandName : string , commandArguments : string [ ] , action : ( _commandName : string , _commandArguments : string [ ] ) => Promise < boolean | ICanExecuteCommandOutput > ) : Promise < boolean > {
109
109
return this . $errors . beginCommand (
110
110
( ) => action . apply ( this , [ commandName , commandArguments ] ) ,
111
111
( ) => this . printHelp ( commandName , commandArguments ) ) ;
112
112
}
113
113
114
- private async tryExecuteCommandAction ( commandName : string , commandArguments : string [ ] ) : Promise < boolean > {
114
+ private async tryExecuteCommandAction ( commandName : string , commandArguments : string [ ] ) : Promise < boolean | ICanExecuteCommandOutput > {
115
115
const command = this . $injector . resolveCommand ( commandName ) ;
116
116
if ( ! command || ( command && ! command . isHierarchicalCommand ) ) {
117
117
this . $options . validateOptions ( command ? command . dashedOptions : null ) ;
@@ -125,19 +125,25 @@ export class CommandsService implements ICommandsService {
125
125
}
126
126
127
127
public async tryExecuteCommand ( commandName : string , commandArguments : string [ ] ) : Promise < void > {
128
- if ( await this . executeCommandAction ( commandName , commandArguments , this . tryExecuteCommandAction ) ) {
128
+ const canExecuteResult : any = await this . executeCommandAction ( commandName , commandArguments , this . tryExecuteCommandAction ) ;
129
+ const canExecute = typeof canExecuteResult === "object" ? canExecuteResult . canExecute : canExecuteResult ;
130
+ const suppressCommandHelp = typeof canExecuteResult === "object" ? canExecuteResult . suppressCommandHelp : false ;
131
+
132
+ if ( canExecute ) {
129
133
await this . executeCommandAction ( commandName , commandArguments , this . executeCommandUnchecked ) ;
130
134
} else {
131
135
// If canExecuteCommand returns false, the command cannot be executed or there's no such command at all.
132
136
const command = this . $injector . resolveCommand ( commandName ) ;
133
137
if ( command ) {
134
- // If command cannot be executed we should print its help.
135
- await this . printHelp ( commandName , commandArguments ) ;
138
+ if ( ! suppressCommandHelp ) {
139
+ // If command cannot be executed we should print its help.
140
+ await this . printHelp ( commandName , commandArguments ) ;
141
+ }
136
142
}
137
143
}
138
144
}
139
145
140
- private async canExecuteCommand ( commandName : string , commandArguments : string [ ] , isDynamicCommand ?: boolean ) : Promise < boolean > {
146
+ private async canExecuteCommand ( commandName : string , commandArguments : string [ ] , isDynamicCommand ?: boolean ) : Promise < boolean | ICanExecuteCommandOutput > {
141
147
const command = this . $injector . resolveCommand ( commandName ) ;
142
148
const beautifiedName = helpers . stringReplaceAll ( commandName , "|" , " " ) ;
143
149
if ( command ) {
0 commit comments