Move FdOptions to Options

This commit is contained in:
sharkdp 2020-04-03 11:39:32 +02:00 committed by David Peter
parent 9f738ad995
commit 65096a653e
5 changed files with 15 additions and 14 deletions

View file

@ -4,8 +4,6 @@ use std::ffi::{OsStr, OsString};
use regex_syntax::hir::Hir; use regex_syntax::hir::Hir;
use regex_syntax::ParserBuilder; use regex_syntax::ParserBuilder;
pub mod opts;
macro_rules! print_error { macro_rules! print_error {
($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*))) ($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*)))
} }

View file

@ -7,6 +7,7 @@ mod exit_codes;
mod filetypes; mod filetypes;
mod filter; mod filter;
mod fshelper; mod fshelper;
mod options;
mod output; mod output;
mod walk; mod walk;
@ -24,7 +25,8 @@ use regex::bytes::{RegexBuilder, RegexSetBuilder};
use crate::exec::CommandTemplate; use crate::exec::CommandTemplate;
use crate::filetypes::FileTypes; use crate::filetypes::FileTypes;
use crate::filter::{SizeFilter, TimeFilter}; 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 // We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/481
#[cfg(all(not(windows), not(target_env = "musl")))] #[cfg(all(not(windows), not(target_env = "musl")))]
@ -208,7 +210,7 @@ fn main() {
} }
} }
let config = FdOptions { let config = Options {
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")

View file

@ -6,7 +6,7 @@ use regex::bytes::RegexSet;
use std::{path::PathBuf, sync::Arc, time::Duration}; use std::{path::PathBuf, sync::Arc, time::Duration};
/// Configuration options for *fd*. /// Configuration options for *fd*.
pub struct FdOptions { pub struct Options {
/// 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,

View file

@ -1,5 +1,5 @@
use crate::exit_codes::ExitCode; use crate::exit_codes::ExitCode;
use crate::internal::opts::FdOptions; use crate::options::Options;
use lscolors::{LsColors, Style}; use lscolors::{LsColors, Style};
use std::borrow::Cow; use std::borrow::Cow;
@ -24,7 +24,7 @@ fn strip_current_dir(pathbuf: &PathBuf) -> &Path {
pub fn print_entry( pub fn print_entry(
stdout: &mut StdoutLock, stdout: &mut StdoutLock,
entry: &PathBuf, entry: &PathBuf,
config: &FdOptions, config: &Options,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
) { ) {
let path = if entry.is_absolute() { 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 { match &config.path_separator {
None => {} None => {}
Some(sep) => { Some(sep) => {
@ -57,7 +57,7 @@ fn replace_path_separator<'a>(config: &FdOptions, path: &mut Cow<'a, str>) {
fn print_entry_colorized( fn print_entry_colorized(
stdout: &mut StdoutLock, stdout: &mut StdoutLock,
path: &Path, path: &Path,
config: &FdOptions, config: &Options,
ls_colors: &LsColors, ls_colors: &LsColors,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
) -> io::Result<()> { ) -> io::Result<()> {
@ -89,7 +89,7 @@ fn print_entry_colorized(
fn print_entry_uncolorized( fn print_entry_uncolorized(
stdout: &mut StdoutLock, stdout: &mut StdoutLock,
path: &Path, path: &Path,
config: &FdOptions, config: &Options,
) -> io::Result<()> { ) -> io::Result<()> {
let separator = if config.null_separator { "\0" } else { "\n" }; let separator = if config.null_separator { "\0" } else { "\n" };

View file

@ -1,7 +1,8 @@
use crate::exec; use crate::exec;
use crate::exit_codes::{merge_exitcodes, ExitCode}; use crate::exit_codes::{merge_exitcodes, ExitCode};
use crate::fshelper; 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 crate::output;
use std::borrow::Cow; 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 /// 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<FdOptions>) -> ExitCode { pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Options>) -> 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()
@ -132,7 +133,7 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -
} }
fn spawn_receiver( fn spawn_receiver(
config: &Arc<FdOptions>, config: &Arc<Options>,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
rx: Receiver<WorkerResult>, rx: Receiver<WorkerResult>,
) -> thread::JoinHandle<ExitCode> { ) -> thread::JoinHandle<ExitCode> {
@ -285,7 +286,7 @@ impl DirEntry {
} }
fn spawn_senders( fn spawn_senders(
config: &Arc<FdOptions>, config: &Arc<Options>,
wants_to_quit: &Arc<AtomicBool>, wants_to_quit: &Arc<AtomicBool>,
pattern: Arc<Regex>, pattern: Arc<Regex>,
parallel_walker: ignore::WalkParallel, parallel_walker: ignore::WalkParallel,