mirror of
https://git.alemi.dev/tci.git
synced 2024-11-23 16:44:48 +01:00
feat: allow executing multiple from dir
This commit is contained in:
parent
1d677a0330
commit
84cefa4b8e
1 changed files with 28 additions and 7 deletions
29
src/main.rs
29
src/main.rs
|
@ -116,14 +116,35 @@ fn tci_hook(repo_path: &std::path::PathBuf, tci_script: &str) -> Result<(), TciE
|
|||
tmp.path(),
|
||||
)?;
|
||||
|
||||
if !tmp.path().join(tci_script).is_file() {
|
||||
return Err(TciError::MissingScript);
|
||||
}
|
||||
let tci_path = tmp.path().join(tci_script);
|
||||
|
||||
if tci_path.is_file() {
|
||||
println!("[=] running tci script for repo '{name}'");
|
||||
std::env::set_current_dir(tmp.path())?;
|
||||
let res = shell_out(tmp.path().join(tci_script));
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
|
||||
res
|
||||
} else if tci_path.is_dir() {
|
||||
std::env::set_current_dir(tmp.path())?;
|
||||
for script in std::fs::read_dir(&tci_path)? {
|
||||
match script {
|
||||
Err(e) => eprintln!("[?] error while listing .tci dir: {e}"),
|
||||
Ok(s) => {
|
||||
println!("[=] running tci script '{:?}' for repo '{name}'", s.file_name());
|
||||
let p = tci_path.clone();
|
||||
let res = shell_out(p.join(s.path()));
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
if let Err(e) = res {
|
||||
eprintln!("[!] error executing script '{:?}': {e}", s.file_name());
|
||||
std::env::set_current_dir(repo_path)?;
|
||||
return Err(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
return Err(TciError::MissingScript);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue