Skip to content

feat: expose a resolveCommand hook allowing cloud publishing though a simple redirect #5234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/common/dispatchers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as queue from "./queue";
import * as path from "path";
import { hook } from "./helpers";

export class CommandDispatcher implements ICommandDispatcher {
constructor(private $logger: ILogger,
// required by the hooksService
protected $injector: IInjector,
private $cancellation: ICancellationService,
private $commandsService: ICommandsService,
private $staticConfig: Config.IStaticConfig,
Expand All @@ -24,7 +27,7 @@ export class CommandDispatcher implements ICommandDispatcher {
}

let commandName = this.getCommandName();
const commandArguments = this.$options.argv._.slice(1);
let commandArguments = this.$options.argv._.slice(1);
const lastArgument: string = _.last(commandArguments);

if (this.$options.help) {
Expand All @@ -36,6 +39,8 @@ export class CommandDispatcher implements ICommandDispatcher {
commandName = "help";
}

({ commandName, commandArguments, argv: process.argv } = await this.resolveCommand(commandName, commandArguments, process.argv));

await this.$cancellation.begin("cli");

await this.$commandsService.tryExecuteCommand(commandName, commandArguments);
Expand All @@ -45,6 +50,12 @@ export class CommandDispatcher implements ICommandDispatcher {
return this.$commandsService.completeCommand();
}

@hook("resolveCommand")
private async resolveCommand(commandName: string, commandArguments: string[], argv: string[]) {
// just a hook point
return { commandName, commandArguments, argv };
}

private getCommandName(): string {
const remaining: string[] = this.$options.argv._;
if (remaining.length > 0) {
Expand Down