with parallel

This commit is contained in:
2022-10-14 23:50:17 +02:00
parent 92660a4c27
commit 9c307a3ec2
3 changed files with 176 additions and 17 deletions

View File

@@ -5,7 +5,7 @@ use clap::Parser;
#[derive(clap::Parser, Clone)]
struct Args {
#[arg(long)]
root_dir: String,
root_dir: Vec<String>,
#[arg(long)]
pattern: Option<String>,
@@ -18,26 +18,38 @@ fn main() -> eyre::Result<()> {
let args = Args::parse();
// Choose dir
let root_dir = args.root_dir;
let mut projects: Vec<PathBuf> = vec![];
let pattern = regex::Regex::new(match args.pattern {
Some(p) => Box::leak(p.into_boxed_str()),
None => ".*\\.git$",
})?;
let pattern = Box::leak(args.pattern.unwrap_or(".git".into()).into_boxed_str());
// Look for dir .git if found add path to map
for entry in walkdir::WalkDir::new(root_dir)
.follow_links(true)
.into_iter()
.filter_map(|e| e.ok())
{
if let Ok(metadata) = entry.metadata() {
if metadata.is_dir() {
let name = entry.file_name().to_string_lossy();
if pattern.is_match(&name) {
projects.push(entry.into_path())
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())
}
}
}
}