gcd_cli/
projectsfinder.rs

1use anyhow::Result;
2use glob::glob;
3use indicatif::ProgressBar;
4
5use crate::lib::to_string;
6
7pub fn find_projects(root_folder: &str) -> Result<Vec<String>> {
8    let spinner = ProgressBar::new_spinner();
9    spinner.set_message(format!(
10        "Searching for git project with base folder {}",
11        root_folder
12    ));
13
14    let mut projects: Vec<String> = vec![];
15    for mut path in glob(&format!("{}/**/.git", root_folder))
16        ?
17        .filter_map(Result::ok)
18        .filter(|p| p.is_dir())
19    {
20        spinner.tick();
21        path.pop();
22        projects.push(to_string(path)?);
23    }
24    spinner.finish_with_message("done.");
25    Ok(projects)
26}
27#[cfg(test)]
28mod tests {
29    use super::*;
30    #[test]
31    fn test_find_projects() -> Result<()> {
32        let projects = find_projects(".")?;
33        assert_eq!(projects.len() >= 1, true);
34        Ok(())
35    }
36}