From f9d62154e2db1337040ce42208c0c50e04175662 Mon Sep 17 00:00:00 2001 From: Daan Boerlage Date: Wed, 31 Aug 2022 02:11:30 +0200 Subject: [PATCH] Make the episode name rule optional with a new cli arg --- src/args.rs | 3 +++ src/main.rs | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/args.rs b/src/args.rs index d9c14e3..ca48c37 100644 --- a/src/args.rs +++ b/src/args.rs @@ -10,4 +10,7 @@ pub struct Args { #[clap(long, value_parser)] pub show_success: bool, + + #[clap(long, value_parser)] + pub episode_name: bool, } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3982d73..070d0b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ fn main() -> Result<()> { for entry in WalkDir::new(params.path) { if let Ok(file) = entry { - check_file(file, &mut stats, ®ex, params.no_emoji, params.show_success); + check_file(file, &mut stats, ®ex, params.no_emoji, params.show_success, params.episode_name); } } @@ -61,11 +61,11 @@ fn main() -> Result<()> { Ok(()) } -fn check_file(file: DirEntry, stats: &mut Stats, regex: &Regex, no_emoji: bool, show_success: bool) -> () { +fn check_file(file: DirEntry, stats: &mut Stats, 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(); - match lint_file_name(&file, filename, regex) { + match lint_file_name(&file, filename, regex, episode_name) { ComplianceStatus::NotMatched => { stats.files += 1; stats.error += 1; @@ -90,7 +90,7 @@ fn check_file(file: DirEntry, stats: &mut Stats, regex: &Regex, no_emoji: bool, } } -fn lint_file_name(file: &DirEntry, filename: &str, regex: &Regex) -> ComplianceStatus { +fn lint_file_name(file: &DirEntry, filename: &str, regex: &Regex, episode_name: bool) -> ComplianceStatus { if let Some(ext) = file.path().extension() { if !VIDEO_EXTENSIONS.contains(&ext.to_str().unwrap()) { return ComplianceStatus::Ignored; @@ -111,10 +111,18 @@ fn lint_file_name(file: &DirEntry, filename: &str, regex: &Regex) -> ComplianceS return ComplianceStatus::NonCompliant(reason); } - if let Some(reason) = HasEpisodeName::check(filename, &captures) { + if let Some(reason) = HasFluff::check(filename, &captures) { return ComplianceStatus::NonCompliant(reason); } + if let Some(reason) = HasEpisodeName::check(filename, &captures) { + return if episode_name { + ComplianceStatus::NonCompliant(reason) + } else { + ComplianceStatus::Compliant + } + } + if let Some(reason) = MissingNameSeparator::check(filename, &captures) { return ComplianceStatus::NonCompliant(reason); } @@ -123,9 +131,5 @@ fn lint_file_name(file: &DirEntry, filename: &str, regex: &Regex) -> ComplianceS return ComplianceStatus::NonCompliant(reason); } - if let Some(reason) = HasFluff::check(filename, &captures) { - return ComplianceStatus::NonCompliant(reason); - } - ComplianceStatus::Compliant } \ No newline at end of file