Skip to content

Commit

Permalink
feat(cli): add run-hook command
Browse files Browse the repository at this point in the history
  • Loading branch information
umbopepato committed Oct 30, 2020
1 parent dba1ba6 commit 66f127f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
22 changes: 0 additions & 22 deletions src/cli/commands/hooks.ts

This file was deleted.

29 changes: 29 additions & 0 deletions src/cli/commands/run_hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Command } from "../../../deps.ts";
import { ConfigData } from "../../load_config.ts";
import { runScript } from "../../run_script.ts";
import { VR_HOOKS } from "../../consts.ts";
import { validateConfigData } from "../../validate_config_data.ts";
import { isScriptObject } from "../../util.ts";

export class RunHookCommand extends Command {
constructor(private configData: ConfigData | null) {
super();
this.description("Run a git hook")
.hidden()
.arguments("<hook:string> [args...]")
.useRawArgs()
.action(async (_, hook: string, ...args: string[]) => {
validateConfigData(this.configData);
if (Deno.env.get(VR_HOOKS) !== "false" && this.configData) {
const script = Object.entries(this.configData.config.scripts)
.find(([_, value]) =>
isScriptObject(value) &&
value.githook === hook
);
if (script) {
await runScript(this.configData, script[0], args);
}
}
});
}
}

0 comments on commit 66f127f

Please sign in to comment.