Refactor to for-loop
@@ -75,31 +75,26 @@ fn run() -> Result<ExitCode> {
.unwrap_or("");
// Get one or more root directories to search.
- let mut dir_vec: Vec<_> = match matches
+ let passed_arguments = matches
.values_of_os("path")
- .or_else(|| matches.values_of_os("search-path"))
- {
- Some(paths) => paths
- .map(|path| {
+ .or_else(|| matches.values_of_os("search-path"));
+
+ // Assign current directory to search vector.
+ let mut dir_vec: Vec<_> = vec![current_directory.to_path_buf()];
+
+ // Assign any valid arguments to search vector.
+ if let Some(paths) = passed_arguments {
+ dir_vec = vec![];
+ for path in paths {
let path_buffer = PathBuf::from(path);
if filesystem::is_dir(&path_buffer) {
- Ok(path_buffer)
- } else {
- Err(anyhow!(
- "Search path '{}' is not a directory.",
- path_buffer.to_string_lossy()
- ))
+ dir_vec.push(path_buffer);
+ }
+ else {
+ print_error(format!("Search path '{}' is not a directory.", path_buffer.to_string_lossy()));
+ }
}
- })
- .inspect(|res| {
- if let Err(e) = res {
- print_error(format!("{}", e))
}
- })
- .filter_map(Result::ok)
- .collect::<Vec<_>>(),
- None => vec![current_directory.to_path_buf()],
- };
if matches.is_present("absolute-path") {
dir_vec = dir_vec
