Skip to content
Myr

Move FdOptions to Options

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by sharkdp · committed by David Peter · parent 9f738ad · Browse files · 6 files+99 added−98 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+99 added−98 removed

  • other:+99 added−98 removed

6 files+99 added−98 removed

modified:src/internal/mod.rs-2 removed
2 unmodified lines
34use regex_syntax::hir::Hir;5use regex_syntax::ParserBuilder;67pub mod opts;87macro_rules! print_error {8 ($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*)))9}10
173 unmodified lines
deleted:src/internal/opts.rs-85 removed
1use crate::exec::CommandTemplate;2use crate::filetypes::FileTypes;3use crate::filter::{SizeFilter, TimeFilter};4use lscolors::LsColors;5use regex::bytes::RegexSet;6use std::{path::PathBuf, sync::Arc, time::Duration};78/// Configuration options for *fd*.9pub struct FdOptions {10 /// Whether the search is case-sensitive or case-insensitive.11 pub case_sensitive: bool,1213 /// Whether to search within the full file path or just the base name (filename or directory14 /// name).15 pub search_full_path: bool,1617 /// Whether to ignore hidden files and directories (or not).18 pub ignore_hidden: bool,1920 /// Whether to respect `.fdignore` files or not.21 pub read_fdignore: bool,2223 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.24 pub read_vcsignore: bool,2526 /// Whether to follow symlinks or not.27 pub follow_links: bool,2829 /// Whether to limit the search to starting file system or not.30 pub one_file_system: bool,3132 /// Whether elements of output should be separated by a null character33 pub null_separator: bool,3435 /// The maximum search depth, or `None` if no maximum search depth should be set.36 ///37 /// A depth of `1` includes all files under the current directory, a depth of `2` also includes38 /// all files under subdirectories of the current directory, etc.39 pub max_depth: Option<usize>,4041 /// The number of threads to use.42 pub threads: usize,4344 /// Time to buffer results internally before streaming to the console. This is useful to45 /// provide a sorted output, in case the total execution time is shorter than46 /// `max_buffer_time`.47 pub max_buffer_time: Option<Duration>,4849 /// `None` if the output should not be colorized. Otherwise, a `LsColors` instance that defines50 /// how to style different filetypes.51 pub ls_colors: Option<LsColors>,5253 /// The type of file to search for. If set to `None`, all file types are displayed. If54 /// set to `Some(..)`, only the types that are specified are shown.55 pub file_types: Option<FileTypes>,5657 /// The extension to search for. Only entries matching the extension will be included.58 ///59 /// The value (if present) will be a lowercase string without leading dots.60 pub extensions: Option<RegexSet>,6162 /// If a value is supplied, each item found will be used to generate and execute commands.63 pub command: Option<Arc<CommandTemplate>>,6465 /// A list of glob patterns that should be excluded from the search.66 pub exclude_patterns: Vec<String>,6768 /// A list of custom ignore files.69 pub ignore_files: Vec<PathBuf>,7071 /// The given constraints on the size of returned files72 pub size_constraints: Vec<SizeFilter>,7374 /// Constraints on last modification time of files75 pub time_constraints: Vec<TimeFilter>,7677 /// Whether or not to display filesystem errors78 pub show_filesystem_errors: bool,7980 /// The separator used to print file paths.81 pub path_separator: Option<String>,8283 /// The maximum number of search results84 pub max_results: Option<usize>,85}
modified:src/main.rs+4 added-2 removed
5 unmodified lines
6mod exit_codes;7mod filetypes;8mod filter;9mod fshelper;10mod options;11mod output;12mod walk;1314use std::env;
9 unmodified lines
2425use crate::exec::CommandTemplate;26use crate::filetypes::FileTypes;27use crate::filter::{SizeFilter, TimeFilter};27use crate::internal::{opts::FdOptions, pattern_has_uppercase_char, transform_args_with_exec};28use crate::internal::{pattern_has_uppercase_char, transform_args_with_exec};29use crate::options::Options;3031// We use jemalloc for performance reasons, see https://github.com/sharkdp/fd/pull/48132#[cfg(all(not(windows), not(target_env = "musl")))]33#[global_allocator]
175 unmodified lines
209 print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);210 }211 }212211 let config = FdOptions {213 let config = Options {214 case_sensitive,215 search_full_path: matches.is_present("full-path"),216 ignore_hidden: !(matches.is_present("hidden")217 || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),
101 unmodified lines
added:src/options.rs+85 added
1use crate::exec::CommandTemplate;2use crate::filetypes::FileTypes;3use crate::filter::{SizeFilter, TimeFilter};4use lscolors::LsColors;5use regex::bytes::RegexSet;6use std::{path::PathBuf, sync::Arc, time::Duration};78/// Configuration options for *fd*.9pub struct Options {10 /// Whether the search is case-sensitive or case-insensitive.11 pub case_sensitive: bool,1213 /// Whether to search within the full file path or just the base name (filename or directory14 /// name).15 pub search_full_path: bool,1617 /// Whether to ignore hidden files and directories (or not).18 pub ignore_hidden: bool,1920 /// Whether to respect `.fdignore` files or not.21 pub read_fdignore: bool,2223 /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.24 pub read_vcsignore: bool,2526 /// Whether to follow symlinks or not.27 pub follow_links: bool,2829 /// Whether to limit the search to starting file system or not.30 pub one_file_system: bool,3132 /// Whether elements of output should be separated by a null character33 pub null_separator: bool,3435 /// The maximum search depth, or `None` if no maximum search depth should be set.36 ///37 /// A depth of `1` includes all files under the current directory, a depth of `2` also includes38 /// all files under subdirectories of the current directory, etc.39 pub max_depth: Option<usize>,4041 /// The number of threads to use.42 pub threads: usize,4344 /// Time to buffer results internally before streaming to the console. This is useful to45 /// provide a sorted output, in case the total execution time is shorter than46 /// `max_buffer_time`.47 pub max_buffer_time: Option<Duration>,4849 /// `None` if the output should not be colorized. Otherwise, a `LsColors` instance that defines50 /// how to style different filetypes.51 pub ls_colors: Option<LsColors>,5253 /// The type of file to search for. If set to `None`, all file types are displayed. If54 /// set to `Some(..)`, only the types that are specified are shown.55 pub file_types: Option<FileTypes>,5657 /// The extension to search for. Only entries matching the extension will be included.58 ///59 /// The value (if present) will be a lowercase string without leading dots.60 pub extensions: Option<RegexSet>,6162 /// If a value is supplied, each item found will be used to generate and execute commands.63 pub command: Option<Arc<CommandTemplate>>,6465 /// A list of glob patterns that should be excluded from the search.66 pub exclude_patterns: Vec<String>,6768 /// A list of custom ignore files.69 pub ignore_files: Vec<PathBuf>,7071 /// The given constraints on the size of returned files72 pub size_constraints: Vec<SizeFilter>,7374 /// Constraints on last modification time of files75 pub time_constraints: Vec<TimeFilter>,7677 /// Whether or not to display filesystem errors78 pub show_filesystem_errors: bool,7980 /// The separator used to print file paths.81 pub path_separator: Option<String>,8283 /// The maximum number of search results84 pub max_results: Option<usize>,85}
modified:src/output.rs+5 added-5 removed
1use crate::exit_codes::ExitCode;2use crate::internal::opts::FdOptions;2use crate::options::Options;3use lscolors::{LsColors, Style};45use std::borrow::Cow;6use std::io::{self, StdoutLock, Write};
16 unmodified lines
2324pub fn print_entry(25 stdout: &mut StdoutLock,26 entry: &PathBuf,27 config: &FdOptions,27 config: &Options,28 wants_to_quit: &Arc<AtomicBool>,29) {30 let path = if entry.is_absolute() {31 entry.as_path()
12 unmodified lines
44 process::exit(ExitCode::GeneralError.into());45 }46}4748fn replace_path_separator<'a>(config: &FdOptions, path: &mut Cow<'a, str>) {48fn replace_path_separator<'a>(config: &Options, path: &mut Cow<'a, str>) {49 match &config.path_separator {50 None => {}51 Some(sep) => {52 *path.to_mut() = path.replace(std::path::MAIN_SEPARATOR, &sep);
3 unmodified lines
5657fn print_entry_colorized(58 stdout: &mut StdoutLock,59 path: &Path,60 config: &FdOptions,60 config: &Options,61 ls_colors: &LsColors,62 wants_to_quit: &Arc<AtomicBool>,63) -> io::Result<()> {64 let default_style = ansi_term::Style::default();
23 unmodified lines
8889fn print_entry_uncolorized(90 stdout: &mut StdoutLock,91 path: &Path,92 config: &FdOptions,92 config: &Options,93) -> io::Result<()> {94 let separator = if config.null_separator { "\0" } else { "\n" };9596 let mut path_str = path.to_string_lossy();
3 unmodified lines
modified:src/walk.rs+5 added-4 removed
1use crate::exec;2use crate::exit_codes::{merge_exitcodes, ExitCode};3use crate::fshelper;4use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH};4use crate::internal::{osstr_to_bytes, MAX_BUFFER_LENGTH};5use crate::options::Options;6use crate::output;78use std::borrow::Cow;9use std::ffi::OsStr;
31 unmodified lines
41///42/// If the `--exec` argument was supplied, this will create a thread pool for executing43/// jobs in parallel from a given command line and the discovered paths. Otherwise, each44/// path will simply be written to standard output.44pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -> ExitCode {45pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<Options>) -> ExitCode {46 let mut path_iter = path_vec.iter();47 let first_path_buf = path_iter48 .next()49 .expect("Error: Path vector can not be empty");
82 unmodified lines
132 exit_code133}134135fn spawn_receiver(135 config: &Arc<FdOptions>,136 config: &Arc<Options>,137 wants_to_quit: &Arc<AtomicBool>,138 rx: Receiver<WorkerResult>,139) -> thread::JoinHandle<ExitCode> {140 let config = Arc::clone(config);
144 unmodified lines
285 }286}287288fn spawn_senders(288 config: &Arc<FdOptions>,289 config: &Arc<Options>,290 wants_to_quit: &Arc<AtomicBool>,291 pattern: Arc<Regex>,292 parallel_walker: ignore::WalkParallel,293 tx: Sender<WorkerResult>,
150 unmodified lines