1
1
import * as queue from "./queue" ;
2
2
import * as path from "path" ;
3
+ import { hook } from "./helpers" ;
3
4
4
5
export class CommandDispatcher implements ICommandDispatcher {
5
6
constructor ( private $logger : ILogger ,
7
+ // required by the hooksService
8
+ protected $injector : IInjector ,
6
9
private $cancellation : ICancellationService ,
7
10
private $commandsService : ICommandsService ,
8
11
private $staticConfig : Config . IStaticConfig ,
@@ -24,7 +27,7 @@ export class CommandDispatcher implements ICommandDispatcher {
24
27
}
25
28
26
29
let commandName = this . getCommandName ( ) ;
27
- const commandArguments = this . $options . argv . _ . slice ( 1 ) ;
30
+ let commandArguments = this . $options . argv . _ . slice ( 1 ) ;
28
31
const lastArgument : string = _ . last ( commandArguments ) ;
29
32
30
33
if ( this . $options . help ) {
@@ -36,6 +39,8 @@ export class CommandDispatcher implements ICommandDispatcher {
36
39
commandName = "help" ;
37
40
}
38
41
42
+ ( { commandName, commandArguments, argv : process . argv } = await this . resolveCommand ( commandName , commandArguments , process . argv ) ) ;
43
+
39
44
await this . $cancellation . begin ( "cli" ) ;
40
45
41
46
await this . $commandsService . tryExecuteCommand ( commandName , commandArguments ) ;
@@ -45,6 +50,12 @@ export class CommandDispatcher implements ICommandDispatcher {
45
50
return this . $commandsService . completeCommand ( ) ;
46
51
}
47
52
53
+ @hook ( "resolveCommand" )
54
+ private async resolveCommand ( commandName : string , commandArguments : string [ ] , argv : string [ ] ) {
55
+ // just a hook point
56
+ return { commandName, commandArguments, argv } ;
57
+ }
58
+
48
59
private getCommandName ( ) : string {
49
60
const remaining : string [ ] = this . $options . argv . _ ;
50
61
if ( remaining . length > 0 ) {
0 commit comments