From ed0b1c45352692270bd93b222bf5eb69e0c7085e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 18 Sep 2024 11:23:11 +0100 Subject: [PATCH] feat: log progress ignoring files listed in .gitignore, .ignore and .rgignore --- Cargo.toml | 1 + src/main.rs | 34 +++++++++++----------------------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 08ea434..928d2c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,4 @@ anyhow = "1.0" regex = "1.10" ureq = "2.10" kxio = "1.2" +ignore = "0.4" diff --git a/src/main.rs b/src/main.rs index 94f3a39..3d8d574 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,12 +25,14 @@ fn main() -> Result<()> { println!("Prefix: {}", config.prefix_pattern); println!("Issues: {}", config.issue_pattern); - // TODO: scan files in workdir - // TODO: ignore files listed in .rgignore .ignore or .gitignore - let mut found_markers = FoundMarkers::default(); - scan_files(&config, &mut found_markers)?; + for file in ignore::Walk::new(config.fs.base()).flatten() { + let path = file.path(); + if config.fs.path_is_file(path)? { + scan_file(path, &config, &mut found_markers)?; + } + } println!("{found_markers:?}"); @@ -82,30 +84,16 @@ impl FoundMarkers { } } -fn scan_files(config: &Config, found_markers: &mut FoundMarkers) -> Result<()> { - scan_dir(config.fs.base(), config, found_markers) -} - -fn scan_dir(dir: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> { - let read_dir = config.fs.dir_read(dir)?; - for entry in read_dir { - match entry? { - DirItem::File(file) => scan_file(&file, config, found_markers), - DirItem::Dir(dir) => scan_dir(&dir, config, found_markers), - DirItem::SymLink(_) | DirItem::Fifo(_) | DirItem::Unsupported(_) => Ok(()), - }?; - } - Ok(()) -} - -fn scan_file(path: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> { +fn scan_file(file: &Path, config: &Config, found_markers: &mut FoundMarkers) -> Result<()> { + println!("file: {}", file.to_string_lossy()); config .fs - .file_read_to_string(path)? + .file_read_to_string(file)? .lines() .enumerate() - .filter_map(|(n, line)| prefix_match(n, line, path, config)) + .filter_map(|(n, line)| prefix_match(n, line, file, config)) .for_each(|marker| { + println!("- {}", marker.line.value); if let Some(issue) = config .issue_pattern .find(&marker.line.value)