mirror of
https://github.com/sharkdp/fd
synced 2024-09-05 08:13:19 +00:00
Minor refactoring
This commit is contained in:
parent
da9af8c1eb
commit
9d3cb69935
25
src/main.rs
25
src/main.rs
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue