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 {
6
+ // required by the hooksService
7
+ get injector ( ) : IInjector {
8
+ return this . $injector ;
9
+ }
10
+
5
11
constructor ( private $logger : ILogger ,
12
+ private $injector : IInjector ,
6
13
private $cancellation : ICancellationService ,
7
14
private $commandsService : ICommandsService ,
8
15
private $staticConfig : Config . IStaticConfig ,
@@ -24,7 +31,7 @@ export class CommandDispatcher implements ICommandDispatcher {
24
31
}
25
32
26
33
let commandName = this . getCommandName ( ) ;
27
- const commandArguments = this . $options . argv . _ . slice ( 1 ) ;
34
+ let commandArguments = this . $options . argv . _ . slice ( 1 ) ;
28
35
const lastArgument : string = _ . last ( commandArguments ) ;
29
36
30
37
if ( this . $options . help ) {
@@ -36,6 +43,8 @@ export class CommandDispatcher implements ICommandDispatcher {
36
43
commandName = "help" ;
37
44
}
38
45
46
+ ( { commandName, commandArguments, argv : process . argv } = await this . resolveCommand ( commandName , commandArguments , process . argv ) ) ;
47
+
39
48
await this . $cancellation . begin ( "cli" ) ;
40
49
41
50
await this . $commandsService . tryExecuteCommand ( commandName , commandArguments ) ;
@@ -45,6 +54,12 @@ export class CommandDispatcher implements ICommandDispatcher {
45
54
return this . $commandsService . completeCommand ( ) ;
46
55
}
47
56
57
+ @hook ( "resolveCommand" )
58
+ private async resolveCommand ( commandName : string , commandArguments : string [ ] , argv : string [ ] ) {
59
+ // just a hook point
60
+ return { commandName, commandArguments, argv } ;
61
+ }
62
+
48
63
private getCommandName ( ) : string {
49
64
const remaining : string [ ] = this . $options . argv . _ ;
50
65
if ( remaining . length > 0 ) {
0 commit comments