Skip to content

Commit

Permalink
Refactor: Rename Options to Config
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasmohrin authored and sharkdp committed Oct 12, 2021
1 parent b8c575c commit 02e9850
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/options.rs → src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -23,14 +23,14 @@ 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;
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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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" };

Expand All @@ -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)
}
Expand All @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 02e9850

Please sign in to comment.