mirror of
https://git.alemi.dev/tci.git
synced 2024-11-23 16:44:48 +01:00
fix: small refactor, show full repo path
This commit is contained in:
parent
4a1fef20fd
commit
83d4b3cbbc
1 changed files with 19 additions and 21 deletions
40
src/main.rs
40
src/main.rs
|
@ -29,6 +29,8 @@ struct TciConfig {
|
||||||
cleanup: Vec<String>,
|
cleanup: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HOME : &str = &std::env::var("HOME").unwrap_or_default();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// load tci config
|
// load tci config
|
||||||
// TODO how could we receive this?
|
// TODO how could we receive this?
|
||||||
|
@ -74,25 +76,17 @@ fn tci(cfg: TciConfig) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
return Ok(()); // we are in whitelist mode and this repo is not whitelisted
|
return Ok(()); // we are in whitelist mode and this repo is not whitelisted
|
||||||
}
|
}
|
||||||
|
|
||||||
// run setup hooks, if provided
|
// run hooks
|
||||||
for setup in cfg.setup {
|
for setup in cfg.setup {
|
||||||
print!("[+] setting up ('{setup}')");
|
print!("[+] setting up ({setup})");
|
||||||
let res = shell(setup)?;
|
println!("{}", shell(setup)?);
|
||||||
if !res.is_empty() {
|
|
||||||
print!(": {res}");
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = tci_hook(&repo_path, &tci_script);
|
let res = tci_hook(&repo_path, &tci_script);
|
||||||
|
|
||||||
for cleanup in cfg.cleanup {
|
for cleanup in cfg.cleanup {
|
||||||
print!("[-] cleaning up ('{cleanup}')");
|
print!("[-] cleaning up ({cleanup}) ");
|
||||||
let res = shell(cleanup)?;
|
println!("{}", shell(cleanup)?);
|
||||||
if !res.is_empty() {
|
|
||||||
print!(": {res}");
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
res?; // only check error AFTER running cleanup hooks
|
res?; // only check error AFTER running cleanup hooks
|
||||||
|
@ -103,13 +97,17 @@ fn tci(cfg: TciConfig) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tci_hook(repo_path: &PathBuf, tci_script: &str) -> Result<(), TciError> {
|
fn tci_hook(repo_path: &PathBuf, tci_script: &str) -> Result<(), TciError> {
|
||||||
let repo_name = repo_path
|
// TODO kind of ew but ehh should do its job
|
||||||
.parent().ok_or(TciError::FsError("missing .git parent"))?
|
let mut name = repo_path.to_string_lossy()
|
||||||
.file_name().ok_or(TciError::FsError("no file name for .git parent"))?
|
.replace(HOME, "");
|
||||||
.to_str().ok_or(TciError::FsError(".git parent file name is not a valid string"))?
|
if name.starts_with('/') {
|
||||||
.to_string();
|
name.remove(0);
|
||||||
|
}
|
||||||
|
if name.ends_with('/') {
|
||||||
|
name.remove(name.chars().count());
|
||||||
|
}
|
||||||
|
|
||||||
let tmp = tempdir::TempDir::new(&format!("tci-{repo_name}"))?;
|
let tmp = tempdir::TempDir::new(&format!("tci-{name}"))?;
|
||||||
|
|
||||||
// TODO allow customizing clone? just clone recursive? just let hook setup submodules?
|
// TODO allow customizing clone? just clone recursive? just let hook setup submodules?
|
||||||
Repository::clone(
|
Repository::clone(
|
||||||
|
@ -124,9 +122,9 @@ fn tci_hook(repo_path: &PathBuf, tci_script: &str) -> Result<(), TciError> {
|
||||||
|
|
||||||
std::env::set_current_dir(tmp.path())?;
|
std::env::set_current_dir(tmp.path())?;
|
||||||
|
|
||||||
println!("[o] running tci script for repo '{repo_name}'");
|
println!("[=] running tci script for repo '{name}'");
|
||||||
let res = shell(tmp.path().join(tci_script))?;
|
let res = shell(tmp.path().join(tci_script))?;
|
||||||
println!("{res}");
|
println!("[:] {}", res.replace("\n", "\n[:]"));
|
||||||
|
|
||||||
std::env::set_current_dir(repo_path)?;
|
std::env::set_current_dir(repo_path)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue