use anyhow::Result; use clap::Parser; use indicatif::ProgressBar; use rust_search::SearchBuilder; use std::io; use std::io::Write; fn main() -> Result<(), Box> { let args = zedl_grep::Args::parse(); let files: Vec = SearchBuilder::default() .location(&args.path) .depth(args.depth) .build() .collect(); let files_only = files.iter().filter(|path| { let path = std::path::Path::new(path); path.is_file() }); let file_count = files_only.clone().count(); let directory_count = files.len() - file_count + 1; let pb = ProgressBar::new(file_count as u64); let mut buf = String::new(); for path in files_only { let path = std::path::Path::new(&path); let result = zedl_grep::process_file(&args, path, &mut buf); if let Err(e) = result { pb.println(format!("Error: {} --- {}", path.to_string_lossy(), e)); } pb.inc(1); } pb.finish_and_clear(); let stdout = io::stdout(); let mut handle = stdout.lock(); handle.write_all(buf.as_bytes())?; handle.flush()?; if args.stats { println!( "\nAnalyzed {} files in {} directories.", file_count, directory_count ); } Ok(()) }