Minor refactoring

This commit is contained in:
sharkdp 2020-05-19 15:37:17 +02:00 committed by David Peter
parent da9af8c1eb
commit 9d3cb69935

View file

@ -79,33 +79,32 @@ fn run() -> Result<ExitCode> {
.values_of_os("path") .values_of_os("path")
.or_else(|| matches.values_of_os("search-path")); .or_else(|| matches.values_of_os("search-path"));
// Assign current directory to search vector. let mut search_paths = if let Some(paths) = passed_arguments {
let mut dir_vec: Vec<_> = vec![current_directory.to_path_buf()]; let mut directories = vec![];
// Assign any valid arguments to search vector.
if let Some(paths) = passed_arguments {
dir_vec = vec![];
for path in paths { for path in paths {
let path_buffer = PathBuf::from(path); let path_buffer = PathBuf::from(path);
if filesystem::is_dir(&path_buffer) { if filesystem::is_dir(&path_buffer) {
dir_vec.push(path_buffer); directories.push(path_buffer);
} } else {
else {
print_error(format!( print_error(format!(
"Search path '{}' is not a directory.", "Search path '{}' is not a directory.",
path_buffer.to_string_lossy() path_buffer.to_string_lossy()
)); ));
} }
} }
}
directories
} else {
vec![current_directory.to_path_buf()]
};
// Check if we have no valid search paths. // Check if we have no valid search paths.
if dir_vec.is_empty() { if search_paths.is_empty() {
return Err(anyhow!("No valid search paths given.")); return Err(anyhow!("No valid search paths given."));
} }
if matches.is_present("absolute-path") { if matches.is_present("absolute-path") {
dir_vec = dir_vec search_paths = search_paths
.iter() .iter()
.map(|path_buffer| { .map(|path_buffer| {
path_buffer path_buffer
@ -410,7 +409,7 @@ fn run() -> Result<ExitCode> {
) )
})?; })?;
walk::scan(&dir_vec, Arc::new(re), Arc::new(config)) walk::scan(&search_paths, Arc::new(re), Arc::new(config))
} }
fn main() { fn main() {