From 43e18129a1b4698afc815bc8d6175f36603b751b Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 1 Sep 2024 12:22:47 +0300 Subject: [PATCH] Removed the screen clear and added an ignore repos cli arg --- src/cli.rs | 3 +++ src/main.rs | 25 ++++++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 575afd6..fea20f7 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,6 +23,9 @@ pub struct CliArgs { #[arg(short, long, num_args(0..), value_hint = ValueHint::DirPath)] pub repos: Option>, + #[arg(short('i'), long("igore"), num_args(0..))] + pub ignored_repos: Option>, + #[arg(short, long, num_args(0..))] pub branches: Option>, diff --git a/src/main.rs b/src/main.rs index 65ed544..0ef8563 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,7 @@ struct Author { } fn main() -> Result<()> { - clear_screen(); + // clear_screen(); let args = CliArgs::parse(); @@ -154,24 +154,33 @@ fn get_color_map() -> Vec { .to_vec() } -fn find_git_repos(scan_path: &path::Path, repos: &mut Vec, _args: &CliArgs) { +fn find_git_repos( + scan_path: &path::Path, + repos: &mut Vec, + ignored_repos: &Vec, + _args: &CliArgs, +) { let Ok(dirs) = scan_path.read_dir() else { return; }; let dirs: Vec<_> = dirs - .filter_map(|f| f.ok()) - .filter(|f| f.file_type().is_ok_and(|t| t.is_dir())) + .filter_map(|d| d.ok()) + .filter(|d| { + let dir_name = d.file_name().to_string_lossy().to_string(); + !ignored_repos.contains(&dir_name) + }) + .filter(|d| d.file_type().is_ok_and(|t| t.is_dir())) .collect_vec(); - let dirs = dirs.iter().map(|f| f.path()); + let dirs = dirs.iter().map(|d| d.path()); for dir in dirs { let filename = dir.file_name().unwrap_or_default().to_string_lossy(); match filename.as_ref() { ".git" => repos.push(dir), - _ => find_git_repos(&dir, repos, _args), + _ => find_git_repos(&dir, repos, ignored_repos, _args), } } } @@ -183,10 +192,12 @@ fn get_commits( ) -> Result<(usize, Vec)> { let mut commits: HashSet = HashSet::new(); + let ignored_repos = args.ignored_repos.as_ref().unwrap_or(&vec![]).to_owned(); + let (repos, branches) = match &args.root_dir { Some(root) => { let mut repos: Vec = vec![]; - find_git_repos(root, &mut repos, &args); + find_git_repos(root, &mut repos, &ignored_repos, &args); let branches = vec!["".to_string(); repos.len()]; (repos, branches) }