use std::path::PathBuf; use clap::Parser; #[derive(clap::Parser, Clone)] struct Args { #[arg(long)] root_dir: Vec, #[arg(long)] pattern: Option, #[arg(long)] projects_file: String, } fn main() -> eyre::Result<()> { let args = Args::parse(); // Choose dir let mut projects: Vec = vec![]; let pattern = Box::leak(args.pattern.unwrap_or(".git".into()).into_boxed_str()); // Look for dir .git if found add path to map for root_dir in args.root_dir { println!("searching: {}", root_dir); for entry in jwalk::WalkDir::new(root_dir) .skip_hidden(false) .follow_links(false) .process_read_dir(|_, _, _, children| { children.retain(|dir_entry_result| { dir_entry_result .as_ref() .map(|dir_entry| { let metadata = match dir_entry.metadata() { Ok(m) => m, Err(_) => return false, }; return metadata.is_dir(); }) .unwrap_or(false) }); }) { match entry { Err(_) => {} Ok(entry) => { let name = entry.file_name().to_string_lossy(); if name.ends_with(&*pattern) { projects.push(entry.path()) } } } } } // Print println!("writing projects"); let projects_str = projects .into_iter() .map(|mut p| { p.pop(); p }) .map(|p| p.to_string_lossy().to_string()) .collect::>(); let content = projects_str.join("\n"); std::fs::write(args.projects_file, content)?; Ok(()) }