From 02e98501125f199e78f555856ef81577053f93bf Mon Sep 17 00:00:00 2001 From: Niklas Mohrin Date: Mon, 23 Aug 2021 13:31:01 +0200 Subject: [PATCH] Refactor: Rename `Options` to `Config` --- src/{options.rs => config.rs} | 2 +- src/main.rs | 14 +++++++------- src/output.rs | 12 ++++++------ src/walk.rs | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) rename src/{options.rs => config.rs} (99%) diff --git a/src/options.rs b/src/config.rs similarity index 99% rename from src/options.rs rename to src/config.rs index 71900dff9..a053e6ef2 100644 --- a/src/options.rs +++ b/src/config.rs @@ -10,7 +10,7 @@ use crate::filter::OwnerFilter; use crate::filter::{SizeFilter, TimeFilter}; /// Configuration options for *fd*. -pub struct Options { +pub struct Config { /// Whether the search is case-sensitive or case-insensitive. pub case_sensitive: bool, diff --git a/src/main.rs b/src/main.rs index 3adb53287..da5fcd9c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ mod app; +mod config; mod error; mod exec; mod exit_codes; mod filesystem; mod filetypes; mod filter; -mod options; mod output; mod regex_helper; mod walk; @@ -23,6 +23,7 @@ use lscolors::LsColors; use normpath::PathExt; use regex::bytes::{RegexBuilder, RegexSetBuilder}; +use crate::config::Config; use crate::error::print_error; use crate::exec::CommandTemplate; use crate::exit_codes::ExitCode; @@ -30,7 +31,6 @@ use crate::filetypes::FileTypes; #[cfg(unix)] use crate::filter::OwnerFilter; use crate::filter::{SizeFilter, TimeFilter}; -use crate::options::Options; use crate::regex_helper::{pattern_has_uppercase_char, pattern_matches_strings_with_leading_dot}; // We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481 @@ -75,7 +75,7 @@ fn run() -> Result { ensure_search_pattern_is_not_a_path(&matches, pattern)?; let pattern_regex = build_pattern_regex(&matches, pattern)?; - let config = construct_options(matches, &pattern_regex)?; + let config = construct_config(matches, &pattern_regex)?; ensure_use_hidden_option_for_leading_dot_pattern(&config, &pattern_regex)?; let re = build_regex(pattern_regex, &config)?; walk::scan(&search_paths, Arc::new(re), Arc::new(config)) @@ -210,7 +210,7 @@ fn check_path_separator_length(path_separator: Option<&str>) -> Result<()> { } } -fn construct_options(matches: clap::ArgMatches, pattern_regex: &str) -> Result { +fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result { // The search will be case-sensitive if the command line flag is set or // if the pattern has an uppercase character (smart case). let case_sensitive = !matches.is_present("ignore-case") @@ -250,7 +250,7 @@ fn construct_options(matches: clap::ArgMatches, pattern_regex: &str) -> Result Result Result<()> { if cfg!(unix) && config.ignore_hidden && pattern_matches_strings_with_leading_dot(pattern_regex) @@ -544,7 +544,7 @@ fn ensure_use_hidden_option_for_leading_dot_pattern( } } -fn build_regex(pattern_regex: String, config: &Options) -> Result { +fn build_regex(pattern_regex: String, config: &Config) -> Result { RegexBuilder::new(&pattern_regex) .case_insensitive(!config.case_sensitive) .dot_matches_new_line(true) diff --git a/src/output.rs b/src/output.rs index 471b8fb9d..536626d1a 100644 --- a/src/output.rs +++ b/src/output.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use lscolors::{LsColors, Style}; +use crate::config::Config; use crate::error::print_error; use crate::exit_codes::ExitCode; use crate::filesystem::strip_current_dir; -use crate::options::Options; fn replace_path_separator(path: &str, new_path_separator: &str) -> String { path.replace(std::path::MAIN_SEPARATOR, new_path_separator) @@ -19,7 +19,7 @@ fn replace_path_separator(path: &str, new_path_separator: &str) -> String { pub fn print_entry( stdout: &mut StdoutLock, entry: &Path, - config: &Options, + config: &Config, wants_to_quit: &Arc, ) { let path = if entry.is_absolute() { @@ -49,7 +49,7 @@ pub fn print_entry( fn print_entry_colorized( stdout: &mut StdoutLock, path: &Path, - config: &Options, + config: &Config, ls_colors: &LsColors, wants_to_quit: &Arc, ) -> io::Result<()> { @@ -85,7 +85,7 @@ fn print_entry_colorized( fn print_entry_uncolorized_base( stdout: &mut StdoutLock, path: &Path, - config: &Options, + config: &Config, ) -> io::Result<()> { let separator = if config.null_separator { "\0" } else { "\n" }; @@ -100,7 +100,7 @@ fn print_entry_uncolorized_base( fn print_entry_uncolorized( stdout: &mut StdoutLock, path: &Path, - config: &Options, + config: &Config, ) -> io::Result<()> { print_entry_uncolorized_base(stdout, path, config) } @@ -109,7 +109,7 @@ fn print_entry_uncolorized( fn print_entry_uncolorized( stdout: &mut StdoutLock, path: &Path, - config: &Options, + config: &Config, ) -> io::Result<()> { use std::os::unix::ffi::OsStrExt; diff --git a/src/walk.rs b/src/walk.rs index 8236e4e36..cb50c4d78 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -15,11 +15,11 @@ use ignore::overrides::OverrideBuilder; use ignore::{self, WalkBuilder}; use regex::bytes::Regex; +use crate::config::Config; use crate::error::print_error; use crate::exec; use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::filesystem; -use crate::options::Options; use crate::output; /// The receiver thread can either be buffering results or directly streaming to the console. @@ -48,7 +48,7 @@ pub const DEFAULT_MAX_BUFFER_TIME: time::Duration = time::Duration::from_millis( /// 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) -> Result { +pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) -> Result { let mut path_iter = path_vec.iter(); let first_path_buf = path_iter .next() @@ -163,7 +163,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 { @@ -333,7 +333,7 @@ impl DirEntry { } fn spawn_senders( - config: &Arc, + config: &Arc, wants_to_quit: &Arc, pattern: Arc, parallel_walker: ignore::WalkParallel,