mirror of https://github.com/sharkdp/fd.git
Refactor: Rename `Options` to `Config`
This commit is contained in:
parent
b8c575cc8f
commit
02e9850112
|
@ -10,7 +10,7 @@ use crate::filter::OwnerFilter;
|
||||||
use crate::filter::{SizeFilter, TimeFilter};
|
use crate::filter::{SizeFilter, TimeFilter};
|
||||||
|
|
||||||
/// Configuration options for *fd*.
|
/// Configuration options for *fd*.
|
||||||
pub struct Options {
|
pub struct Config {
|
||||||
/// Whether the search is case-sensitive or case-insensitive.
|
/// Whether the search is case-sensitive or case-insensitive.
|
||||||
pub case_sensitive: bool,
|
pub case_sensitive: bool,
|
||||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,11 +1,11 @@
|
||||||
mod app;
|
mod app;
|
||||||
|
mod config;
|
||||||
mod error;
|
mod error;
|
||||||
mod exec;
|
mod exec;
|
||||||
mod exit_codes;
|
mod exit_codes;
|
||||||
mod filesystem;
|
mod filesystem;
|
||||||
mod filetypes;
|
mod filetypes;
|
||||||
mod filter;
|
mod filter;
|
||||||
mod options;
|
|
||||||
mod output;
|
mod output;
|
||||||
mod regex_helper;
|
mod regex_helper;
|
||||||
mod walk;
|
mod walk;
|
||||||
|
@ -23,6 +23,7 @@ use lscolors::LsColors;
|
||||||
use normpath::PathExt;
|
use normpath::PathExt;
|
||||||
use regex::bytes::{RegexBuilder, RegexSetBuilder};
|
use regex::bytes::{RegexBuilder, RegexSetBuilder};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
use crate::error::print_error;
|
use crate::error::print_error;
|
||||||
use crate::exec::CommandTemplate;
|
use crate::exec::CommandTemplate;
|
||||||
use crate::exit_codes::ExitCode;
|
use crate::exit_codes::ExitCode;
|
||||||
|
@ -30,7 +31,6 @@ use crate::filetypes::FileTypes;
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use crate::filter::OwnerFilter;
|
use crate::filter::OwnerFilter;
|
||||||
use crate::filter::{SizeFilter, TimeFilter};
|
use crate::filter::{SizeFilter, TimeFilter};
|
||||||
use crate::options::Options;
|
|
||||||
use crate::regex_helper::{pattern_has_uppercase_char, pattern_matches_strings_with_leading_dot};
|
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
|
// 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)?;
|
ensure_search_pattern_is_not_a_path(&matches, pattern)?;
|
||||||
let pattern_regex = build_pattern_regex(&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)?;
|
ensure_use_hidden_option_for_leading_dot_pattern(&config, &pattern_regex)?;
|
||||||
let re = build_regex(pattern_regex, &config)?;
|
let re = build_regex(pattern_regex, &config)?;
|
||||||
walk::scan(&search_paths, Arc::new(re), Arc::new(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
|
// The search will be case-sensitive if the command line flag is set or
|
||||||
// if the pattern has an uppercase character (smart case).
|
// if the pattern has an uppercase character (smart case).
|
||||||
let case_sensitive = !matches.is_present("ignore-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)?;
|
let command = extract_command(&matches, path_separator.as_deref(), colored_output)?;
|
||||||
|
|
||||||
Ok(Options {
|
Ok(Config {
|
||||||
case_sensitive,
|
case_sensitive,
|
||||||
search_full_path: matches.is_present("full-path"),
|
search_full_path: matches.is_present("full-path"),
|
||||||
ignore_hidden: !(matches.is_present("hidden")
|
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(
|
fn ensure_use_hidden_option_for_leading_dot_pattern(
|
||||||
config: &Options,
|
config: &Config,
|
||||||
pattern_regex: &str,
|
pattern_regex: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if cfg!(unix) && config.ignore_hidden && pattern_matches_strings_with_leading_dot(pattern_regex)
|
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)
|
RegexBuilder::new(&pattern_regex)
|
||||||
.case_insensitive(!config.case_sensitive)
|
.case_insensitive(!config.case_sensitive)
|
||||||
.dot_matches_new_line(true)
|
.dot_matches_new_line(true)
|
||||||
|
|
|
@ -6,10 +6,10 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use lscolors::{LsColors, Style};
|
use lscolors::{LsColors, Style};
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
use crate::error::print_error;
|
use crate::error::print_error;
|
||||||
use crate::exit_codes::ExitCode;
|
use crate::exit_codes::ExitCode;
|
||||||
use crate::filesystem::strip_current_dir;
|
use crate::filesystem::strip_current_dir;
|
||||||
use crate::options::Options;
|
|
||||||
|
|
||||||
fn replace_path_separator(path: &str, new_path_separator: &str) -> String {
|
fn replace_path_separator(path: &str, new_path_separator: &str) -> String {
|
||||||
path.replace(std::path::MAIN_SEPARATOR, new_path_separator)
|
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(
|
pub fn print_entry(
|
||||||
stdout: &mut StdoutLock,
|
stdout: &mut StdoutLock,
|
||||||
entry: &Path,
|
entry: &Path,
|
||||||
config: &Options,
|
config: &Config,
|
||||||
wants_to_quit: &Arc<AtomicBool>,
|
wants_to_quit: &Arc<AtomicBool>,
|
||||||
) {
|
) {
|
||||||
let path = if entry.is_absolute() {
|
let path = if entry.is_absolute() {
|
||||||
|
@ -49,7 +49,7 @@ pub fn print_entry(
|
||||||
fn print_entry_colorized(
|
fn print_entry_colorized(
|
||||||
stdout: &mut StdoutLock,
|
stdout: &mut StdoutLock,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
config: &Options,
|
config: &Config,
|
||||||
ls_colors: &LsColors,
|
ls_colors: &LsColors,
|
||||||
wants_to_quit: &Arc<AtomicBool>,
|
wants_to_quit: &Arc<AtomicBool>,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
|
@ -85,7 +85,7 @@ fn print_entry_colorized(
|
||||||
fn print_entry_uncolorized_base(
|
fn print_entry_uncolorized_base(
|
||||||
stdout: &mut StdoutLock,
|
stdout: &mut StdoutLock,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
config: &Options,
|
config: &Config,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let separator = if config.null_separator { "\0" } else { "\n" };
|
let separator = if config.null_separator { "\0" } else { "\n" };
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ fn print_entry_uncolorized_base(
|
||||||
fn print_entry_uncolorized(
|
fn print_entry_uncolorized(
|
||||||
stdout: &mut StdoutLock,
|
stdout: &mut StdoutLock,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
config: &Options,
|
config: &Config,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
print_entry_uncolorized_base(stdout, path, config)
|
print_entry_uncolorized_base(stdout, path, config)
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ fn print_entry_uncolorized(
|
||||||
fn print_entry_uncolorized(
|
fn print_entry_uncolorized(
|
||||||
stdout: &mut StdoutLock,
|
stdout: &mut StdoutLock,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
config: &Options,
|
config: &Config,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
|
||||||
|
|
|
@ -15,11 +15,11 @@ use ignore::overrides::OverrideBuilder;
|
||||||
use ignore::{self, WalkBuilder};
|
use ignore::{self, WalkBuilder};
|
||||||
use regex::bytes::Regex;
|
use regex::bytes::Regex;
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
use crate::error::print_error;
|
use crate::error::print_error;
|
||||||
use crate::exec;
|
use crate::exec;
|
||||||
use crate::exit_codes::{merge_exitcodes, ExitCode};
|
use crate::exit_codes::{merge_exitcodes, ExitCode};
|
||||||
use crate::filesystem;
|
use crate::filesystem;
|
||||||
use crate::options::Options;
|
|
||||||
use crate::output;
|
use crate::output;
|
||||||
|
|
||||||
/// The receiver thread can either be buffering results or directly streaming to the console.
|
/// 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
|
/// 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
|
/// jobs in parallel from a given command line and the discovered paths. Otherwise, each
|
||||||
/// path will simply be written to standard output.
|
/// 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 mut path_iter = path_vec.iter();
|
||||||
let first_path_buf = path_iter
|
let first_path_buf = path_iter
|
||||||
.next()
|
.next()
|
||||||
|
@ -163,7 +163,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Options>) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_receiver(
|
fn spawn_receiver(
|
||||||
config: &Arc<Options>,
|
config: &Arc<Config>,
|
||||||
wants_to_quit: &Arc<AtomicBool>,
|
wants_to_quit: &Arc<AtomicBool>,
|
||||||
rx: Receiver<WorkerResult>,
|
rx: Receiver<WorkerResult>,
|
||||||
) -> thread::JoinHandle<ExitCode> {
|
) -> thread::JoinHandle<ExitCode> {
|
||||||
|
@ -333,7 +333,7 @@ impl DirEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_senders(
|
fn spawn_senders(
|
||||||
config: &Arc<Options>,
|
config: &Arc<Config>,
|
||||||
wants_to_quit: &Arc<AtomicBool>,
|
wants_to_quit: &Arc<AtomicBool>,
|
||||||
pattern: Arc<Regex>,
|
pattern: Arc<Regex>,
|
||||||
parallel_walker: ignore::WalkParallel,
|
parallel_walker: ignore::WalkParallel,
|
||||||
|
|
Loading…
Reference in New Issue