Make the episode name rule optional with a new cli arg
This commit is contained in:
parent
2937e98988
commit
f9d62154e2
2 changed files with 16 additions and 9 deletions
|
@ -10,4 +10,7 @@ pub struct Args {
|
|||
|
||||
#[clap(long, value_parser)]
|
||||
pub show_success: bool,
|
||||
|
||||
#[clap(long, value_parser)]
|
||||
pub episode_name: bool,
|
||||
}
|
22
src/main.rs
22
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
|
||||
}
|
Loading…
Reference in a new issue