Improve the search_for
utilty function and reduce the nested code
This commit is contained in:
parent
a5dd196937
commit
c71992fc52
2 changed files with 11 additions and 12 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
mod arguments;
|
||||
mod cmus;
|
||||
mod utils;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ pub fn search_for(
|
|||
) -> std::io::Result<Option<String>> {
|
||||
// Search in the track directory.
|
||||
for entry in std::fs::read_dir(search_directory)? {
|
||||
if let Ok(entry) = entry {
|
||||
if let Ok(file_type) = entry.file_type() {
|
||||
let Ok(entry) = entry else { continue; };
|
||||
let Ok(file_type) = entry.file_type() else { continue; };
|
||||
if file_type.is_file() {
|
||||
let Ok(file_name) = entry.file_name().into_string() else { continue; };
|
||||
// Check if the file name matches any of the regular expressions.
|
||||
|
@ -23,8 +23,6 @@ pub fn search_for(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// If the max depth is reached, return `None`.
|
||||
if max_depth == 0 {
|
||||
Ok(None)
|
||||
|
|
Loading…
Reference in a new issue