diff --git a/src/main.rs b/src/main.rs index 1856b0e..3a148b5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,6 +36,11 @@ impl Display for Stats { } } +struct Context { + current_folder: String, + has_printed_folder: bool, +} + fn main() -> Result<()> { let params = Args::parse(); @@ -48,11 +53,16 @@ fn main() -> Result<()> { error: 0, }; + let mut ctx = Context { + current_folder: "".to_string(), + has_printed_folder: false, + }; + let regex = Regex::new(SERIES_REGEX).unwrap(); for entry in WalkDir::new(params.path) { if let Ok(file) = entry { - check_file(file, &mut stats, ®ex, params.no_emoji, params.show_success, params.episode_name); + check_file(file, &mut stats, &mut ctx, ®ex, params.no_emoji, params.show_success, params.episode_name); } } @@ -61,7 +71,7 @@ fn main() -> Result<()> { Ok(()) } -fn check_file(file: DirEntry, stats: &mut Stats, regex: &Regex, no_emoji: bool, show_success: bool, episode_name: bool) -> () { +fn check_file(file: DirEntry, stats: &mut Stats, ctx: &mut Context, regex: &Regex, no_emoji: bool, show_success: bool, episode_name: bool) -> () { let file_type = file.file_type(); if file_type.is_file() { let filename = file.file_name().to_str().unwrap(); @@ -69,10 +79,18 @@ fn check_file(file: DirEntry, stats: &mut Stats, regex: &Regex, no_emoji: bool, ComplianceStatus::NotMatched => { stats.files += 1; stats.error += 1; - println!("{} {} --- (Failed to match)", get_status_icon(StatusIcon::Failure, no_emoji), filename) + if !ctx.has_printed_folder { + println!("\n\n=== {} {}", get_status_icon(StatusIcon::Directory, no_emoji), ctx.current_folder); + ctx.has_printed_folder = true; + } + println!("{} {} --- (Failed to match)", get_status_icon(StatusIcon::Failure, no_emoji), filename); } ComplianceStatus::NonCompliant(reason) => { stats.files += 1; + if !ctx.has_printed_folder { + println!("\n\n=== {} {}", get_status_icon(StatusIcon::Directory, no_emoji), ctx.current_folder); + ctx.has_printed_folder = true; + } stats.warning += 1; println!("{} {} --- ({})", get_status_icon(StatusIcon::Warning, no_emoji), filename, reason); } @@ -80,13 +98,14 @@ fn check_file(file: DirEntry, stats: &mut Stats, regex: &Regex, no_emoji: bool, stats.files += 1; stats.success += 1; if show_success { - println!("{} {}", get_status_icon(StatusIcon::Success, no_emoji), filename) + println!("{} {}", get_status_icon(StatusIcon::Success, no_emoji), filename); } } ComplianceStatus::Ignored => {} } } else if file_type.is_dir() { - println!("\n\n=== {} {}", get_status_icon(StatusIcon::Directory, no_emoji), file.path().display()) + ctx.current_folder = file.path().display().to_string(); + ctx.has_printed_folder = false; } }