feat: allow executing multiple from dir

This commit is contained in:
əlemi 2024-02-13 22:55:35 +01:00
parent 1d677a0330
commit 84cefa4b8e
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -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);
}
}