Skip to content

Commit 887f674

Browse files
committed
Run hooks from output dir
1 parent cb55668 commit 887f674

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

examples/hooks/greet.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env python3
2+
import os
23

3-
print("Hello {{greeting_recipient}}!")
4+
print(f"Hello {{greeting_recipient}} from {os.getcwd()}!")

src/main.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,13 @@ macro_rules! bail_if_err {
107107
}};
108108
}
109109

110-
fn execute_hook(hook: &HookFile) -> Result<()> {
110+
fn execute_hook(hook: &HookFile, output_dir: &PathBuf) -> Result<()> {
111111
terminal::bold(&format!(" - {}\n", hook.name()));
112-
match StdCommand::new(hook.path()).status() {
112+
let mut command = StdCommand::new(hook.path());
113+
if output_dir.exists() {
114+
command.current_dir(output_dir);
115+
}
116+
match command.status() {
113117
Ok(code) => {
114118
if code.success() {
115119
Ok(())
@@ -155,7 +159,7 @@ fn main() {
155159
if cli.run_hooks && !pre_gen_hooks.is_empty() {
156160
terminal::bold("Running pre-gen hooks...\n");
157161
for hook in &pre_gen_hooks {
158-
bail_if_err!(execute_hook(hook));
162+
bail_if_err!(execute_hook(hook, &cli.output_dir));
159163
}
160164
println!();
161165
}
@@ -168,7 +172,7 @@ fn main() {
168172
if cli.run_hooks && !post_gen_hooks.is_empty() {
169173
terminal::bold("Running post-gen hooks...\n");
170174
for hook in &post_gen_hooks {
171-
bail_if_err!(execute_hook(hook));
175+
bail_if_err!(execute_hook(hook, &cli.output_dir));
172176
}
173177
println!();
174178
}

0 commit comments

Comments
 (0)