Refactor: Rename `Options` to `Config`

This commit is contained in:
Niklas Mohrin 2021-08-23 13:31:01 +02:00 committed by David Peter
parent b8c575cc8f
commit 02e9850112
4 changed files with 18 additions and 18 deletions

View File

@ -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,

View File

@ -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<ExitCode> {
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<Options> {
fn construct_config(matches: clap::ArgMatches, pattern_regex: &str) -> Result<Config> {
// 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<O
};
let command = extract_command(&matches, path_separator.as_deref(), colored_output)?;
Ok(Options {
Ok(Config {
case_sensitive,
search_full_path: matches.is_present("full-path"),
ignore_hidden: !(matches.is_present("hidden")
@ -529,7 +529,7 @@ fn extract_time_constraints(matches: &clap::ArgMatches) -> Result<Vec<TimeFilter
}
fn ensure_use_hidden_option_for_leading_dot_pattern(
config: &Options,
config: &Config,
pattern_regex: &str,
) -> 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<regex::bytes::Regex> {
fn build_regex(pattern_regex: String, config: &Config) -> Result<regex::bytes::Regex> {
RegexBuilder::new(&pattern_regex)
.case_insensitive(!config.case_sensitive)
.dot_matches_new_line(true)

View File

@ -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<AtomicBool>,
) {
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<AtomicBool>,
) -> 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;

View File

@ -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<Regex>, config: Arc<Options>) -> Result<ExitCode> {
pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Config>) -> Result<ExitCode> {
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<Regex>, config: Arc<Options>) ->
}
fn spawn_receiver(
config: &Arc<Options>,
config: &Arc<Config>,
wants_to_quit: &Arc<AtomicBool>,
rx: Receiver<WorkerResult>,
) -> thread::JoinHandle<ExitCode> {
@ -333,7 +333,7 @@ impl DirEntry {
}
fn spawn_senders(
config: &Arc<Options>,
config: &Arc<Config>,
wants_to_quit: &Arc<AtomicBool>,
pattern: Arc<Regex>,
parallel_walker: ignore::WalkParallel,