From 84cefa4b8e15f60662df503253494cb38f7674f8 Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 13 Feb 2024 22:55:35 +0100 Subject: [PATCH] feat: allow executing multiple from dir --- src/main.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index a09d2b2..cbba710 100644 --- a/src/main.rs +++ b/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() { + 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); } - 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 }