Skip to content

Commit 91b11e5

Browse files
committed
feat: expose a resolveCommand hook allowing cloud publishing though a simple redirect
1 parent 732f1a0 commit 91b11e5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/common/dispatchers.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import * as queue from "./queue";
22
import * as path from "path";
3+
import { hook } from "./helpers";
34

45
export class CommandDispatcher implements ICommandDispatcher {
6+
// required by the hooksService
7+
get injector(): IInjector {
8+
return this.$injector;
9+
}
10+
511
constructor(private $logger: ILogger,
12+
private $injector: IInjector,
613
private $cancellation: ICancellationService,
714
private $commandsService: ICommandsService,
815
private $staticConfig: Config.IStaticConfig,
@@ -24,7 +31,7 @@ export class CommandDispatcher implements ICommandDispatcher {
2431
}
2532

2633
let commandName = this.getCommandName();
27-
const commandArguments = this.$options.argv._.slice(1);
34+
let commandArguments = this.$options.argv._.slice(1);
2835
const lastArgument: string = _.last(commandArguments);
2936

3037
if (this.$options.help) {
@@ -36,6 +43,8 @@ export class CommandDispatcher implements ICommandDispatcher {
3643
commandName = "help";
3744
}
3845

46+
({ commandName, commandArguments, argv: process.argv } = await this.resolveCommand(commandName, commandArguments, process.argv));
47+
3948
await this.$cancellation.begin("cli");
4049

4150
await this.$commandsService.tryExecuteCommand(commandName, commandArguments);
@@ -45,6 +54,12 @@ export class CommandDispatcher implements ICommandDispatcher {
4554
return this.$commandsService.completeCommand();
4655
}
4756

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+
4863
private getCommandName(): string {
4964
const remaining: string[] = this.$options.argv._;
5065
if (remaining.length > 0) {

0 commit comments

Comments
 (0)