From 65096a653ea85ae9cf28620876f6ac549605dc24 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 3 Apr 2020 11:39:32 +0200 Subject: [PATCH] Move FdOptions to Options --- src/internal/mod.rs | 2 -- src/main.rs | 6 ++++-- src/{internal/opts.rs => options.rs} | 2 +- src/output.rs | 10 +++++----- src/walk.rs | 9 +++++---- 5 files changed, 15 insertions(+), 14 deletions(-) rename src/{internal/opts.rs => options.rs} (99%) diff --git a/src/internal/mod.rs b/src/internal/mod.rs index 08fe18a..90c421a 100644 --- a/src/internal/mod.rs +++ b/src/internal/mod.rs @@ -4,8 +4,6 @@ use std::ffi::{OsStr, OsString}; use regex_syntax::hir::Hir; use regex_syntax::ParserBuilder; -pub mod opts; - macro_rules! print_error { ($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*))) } diff --git a/src/main.rs b/src/main.rs index 36a1b22..2d97180 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ mod exit_codes; mod filetypes; mod filter; mod fshelper; +mod options; mod output; mod walk; @@ -24,7 +25,8 @@ use regex::bytes::{RegexBuilder, RegexSetBuilder}; use crate::exec::CommandTemplate; use crate::filetypes::FileTypes; use crate::filter::{SizeFilter, TimeFilter}; -use crate::internal::{opts::FdOptions, pattern_has_uppercase_char, transform_args_with_exec}; +use crate::internal::{pattern_has_uppercase_char, transform_args_with_exec}; +use crate::options::Options; // We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481 #[cfg(all(not(windows), not(target_env = "musl")))] @@ -208,7 +210,7 @@ fn main() { } } - let config = FdOptions { + let config = Options { case_sensitive, search_full_path: matches.is_present("full-path"), ignore_hidden: !(matches.is_present("hidden") diff --git a/src/internal/opts.rs b/src/options.rs similarity index 99% rename from src/internal/opts.rs rename to src/options.rs index dfc8cbe..12fdfc0 100644 --- a/src/internal/opts.rs +++ b/src/options.rs @@ -6,7 +6,7 @@ use regex::bytes::RegexSet; use std::{path::PathBuf, sync::Arc, time::Duration}; /// Configuration options for *fd*. -pub struct FdOptions { +pub struct Options { /// Whether the search is case-sensitive or case-insensitive. pub case_sensitive: bool, diff --git a/src/output.rs b/src/output.rs index a38f9f5..198c3e1 100644 --- a/src/output.rs +++ b/src/output.rs @@ -1,5 +1,5 @@ use crate::exit_codes::ExitCode; -use crate::internal::opts::FdOptions; +use crate::options::Options; use lscolors::{LsColors, Style}; use std::borrow::Cow; @@ -24,7 +24,7 @@ fn strip_current_dir(pathbuf: &PathBuf) -> &Path { pub fn print_entry( stdout: &mut StdoutLock, entry: &PathBuf, - config: &FdOptions, + config: &Options, wants_to_quit: &Arc, ) { let path = if entry.is_absolute() { @@ -45,7 +45,7 @@ pub fn print_entry( } } -fn replace_path_separator<'a>(config: &FdOptions, path: &mut Cow<'a, str>) { +fn replace_path_separator<'a>(config: &Options, path: &mut Cow<'a, str>) { match &config.path_separator { None => {} Some(sep) => { @@ -57,7 +57,7 @@ fn replace_path_separator<'a>(config: &FdOptions, path: &mut Cow<'a, str>) { fn print_entry_colorized( stdout: &mut StdoutLock, path: &Path, - config: &FdOptions, + config: &Options, ls_colors: &LsColors, wants_to_quit: &Arc, ) -> io::Result<()> { @@ -89,7 +89,7 @@ fn print_entry_colorized( fn print_entry_uncolorized( stdout: &mut StdoutLock, path: &Path, - config: &FdOptions, + config: &Options, ) -> io::Result<()> { let separator = if config.null_separator { "\0" } else { "\n" }; diff --git a/src/walk.rs b/src/walk.rs index 0d3d859..f5aef77 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -1,7 +1,8 @@ use crate::exec; use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::fshelper; -use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH}; +use crate::internal::{osstr_to_bytes, MAX_BUFFER_LENGTH}; +use crate::options::Options; use crate::output; use std::borrow::Cow; @@ -41,7 +42,7 @@ pub enum WorkerResult { /// If the `--exec` argument was supplied, this will create a thread pool for executing /// jobs in parallel from a given command line and the discovered paths. Otherwise, each /// path will simply be written to standard output. -pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> ExitCode { +pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> ExitCode { let mut path_iter = path_vec.iter(); let first_path_buf = path_iter .next() @@ -132,7 +133,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) - } fn spawn_receiver( - config: &Arc, + config: &Arc, wants_to_quit: &Arc, rx: Receiver, ) -> thread::JoinHandle { @@ -285,7 +286,7 @@ impl DirEntry { } fn spawn_senders( - config: &Arc, + config: &Arc, wants_to_quit: &Arc, pattern: Arc, parallel_walker: ignore::WalkParallel,