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
Provenance
- Commit
65096a6- Tree
1a1df38- Author
sharkdp <davidpeter@web.de>- Committer
David Peter <sharkdp@users.noreply.github.com>- Parent
9f738ad
6 files changed+99 added−98 removed
modified:src/internal/mod.rs-2 removed
2 unmodified lines3 4 use regex_syntax::hir::Hir;5 use regex_syntax::ParserBuilder;6 7-pub mod opts;8-7 macro_rules! print_error {8 ($($arg:tt)*) => (eprintln!("[fd error]: {}", format!($($arg)*)))9 }10 173 unmodified linesdeleted:src/internal/opts.rs-85 removed
1-use crate::exec::CommandTemplate;2-use crate::filetypes::FileTypes;3-use crate::filter::{SizeFilter, TimeFilter};4-use lscolors::LsColors;5-use regex::bytes::RegexSet;6-use std::{path::PathBuf, sync::Arc, time::Duration};7-8-/// Configuration options for *fd*.9-pub struct FdOptions {10- /// Whether the search is case-sensitive or case-insensitive.11- pub case_sensitive: bool,12-13- /// Whether to search within the full file path or just the base name (filename or directory14- /// name).15- pub search_full_path: bool,16-17- /// Whether to ignore hidden files and directories (or not).18- pub ignore_hidden: bool,19-20- /// Whether to respect `.fdignore` files or not.21- pub read_fdignore: bool,22-23- /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.24- pub read_vcsignore: bool,25-26- /// Whether to follow symlinks or not.27- pub follow_links: bool,28-29- /// Whether to limit the search to starting file system or not.30- pub one_file_system: bool,31-32- /// Whether elements of output should be separated by a null character33- pub null_separator: bool,34-35- /// 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>,40-41- /// The number of threads to use.42- pub threads: usize,43-44- /// 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>,48-49- /// `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>,52-53- /// 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>,56-57- /// 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>,61-62- /// If a value is supplied, each item found will be used to generate and execute commands.63- pub command: Option<Arc<CommandTemplate>>,64-65- /// A list of glob patterns that should be excluded from the search.66- pub exclude_patterns: Vec<String>,67-68- /// A list of custom ignore files.69- pub ignore_files: Vec<PathBuf>,70-71- /// The given constraints on the size of returned files72- pub size_constraints: Vec<SizeFilter>,73-74- /// Constraints on last modification time of files75- pub time_constraints: Vec<TimeFilter>,76-77- /// Whether or not to display filesystem errors78- pub show_filesystem_errors: bool,79-80- /// The separator used to print file paths.81- pub path_separator: Option<String>,82-83- /// The maximum number of search results84- pub max_results: Option<usize>,85-}modified:src/main.rs+4 added-2 removed
5 unmodified lines6 mod exit_codes;7 mod filetypes;8 mod filter;9 mod fshelper;10+mod options;11 mod output;12 mod walk;13 14 use std::env;9 unmodified lines24 25 use crate::exec::CommandTemplate;26 use crate::filetypes::FileTypes;27 use crate::filter::{SizeFilter, TimeFilter};27-use crate::internal::{opts::FdOptions, pattern_has_uppercase_char, transform_args_with_exec};28+use crate::internal::{pattern_has_uppercase_char, transform_args_with_exec};29+use crate::options::Options;30 31 // 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 lines209 print_error_and_exit!("'{}' is not a valid date or duration. See 'fd --help'.", t);210 }211 }212 211- 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 linesadded:src/options.rs+85 added
1+use crate::exec::CommandTemplate;2+use crate::filetypes::FileTypes;3+use crate::filter::{SizeFilter, TimeFilter};4+use lscolors::LsColors;5+use regex::bytes::RegexSet;6+use std::{path::PathBuf, sync::Arc, time::Duration};7+8+/// Configuration options for *fd*.9+pub struct Options {10+ /// Whether the search is case-sensitive or case-insensitive.11+ pub case_sensitive: bool,12+13+ /// Whether to search within the full file path or just the base name (filename or directory14+ /// name).15+ pub search_full_path: bool,16+17+ /// Whether to ignore hidden files and directories (or not).18+ pub ignore_hidden: bool,19+20+ /// Whether to respect `.fdignore` files or not.21+ pub read_fdignore: bool,22+23+ /// Whether to respect VCS ignore files (`.gitignore`, ..) or not.24+ pub read_vcsignore: bool,25+26+ /// Whether to follow symlinks or not.27+ pub follow_links: bool,28+29+ /// Whether to limit the search to starting file system or not.30+ pub one_file_system: bool,31+32+ /// Whether elements of output should be separated by a null character33+ pub null_separator: bool,34+35+ /// 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>,40+41+ /// The number of threads to use.42+ pub threads: usize,43+44+ /// 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>,48+49+ /// `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>,52+53+ /// 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>,56+57+ /// 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>,61+62+ /// If a value is supplied, each item found will be used to generate and execute commands.63+ pub command: Option<Arc<CommandTemplate>>,64+65+ /// A list of glob patterns that should be excluded from the search.66+ pub exclude_patterns: Vec<String>,67+68+ /// A list of custom ignore files.69+ pub ignore_files: Vec<PathBuf>,70+71+ /// The given constraints on the size of returned files72+ pub size_constraints: Vec<SizeFilter>,73+74+ /// Constraints on last modification time of files75+ pub time_constraints: Vec<TimeFilter>,76+77+ /// Whether or not to display filesystem errors78+ pub show_filesystem_errors: bool,79+80+ /// The separator used to print file paths.81+ pub path_separator: Option<String>,82+83+ /// The maximum number of search results84+ pub max_results: Option<usize>,85+}modified:src/output.rs+5 added-5 removed
1 use crate::exit_codes::ExitCode;2-use crate::internal::opts::FdOptions;2+use crate::options::Options;3 use lscolors::{LsColors, Style};4 5 use std::borrow::Cow;6 use std::io::{self, StdoutLock, Write};16 unmodified lines23 24 pub 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 lines44 process::exit(ExitCode::GeneralError.into());45 }46 }47 48-fn replace_path_separator<'a>(config: &FdOptions, path: &mut Cow<'a, str>) {48+fn 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 lines56 57 fn 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 lines88 89 fn 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" };95 96 let mut path_str = path.to_string_lossy();3 unmodified linesmodified:src/walk.rs+5 added-4 removed
1 use crate::exec;2 use crate::exit_codes::{merge_exitcodes, ExitCode};3 use crate::fshelper;4-use crate::internal::{opts::FdOptions, osstr_to_bytes, MAX_BUFFER_LENGTH};4+use crate::internal::{osstr_to_bytes, MAX_BUFFER_LENGTH};5+use crate::options::Options;6 use crate::output;7 8 use std::borrow::Cow;9 use std::ffi::OsStr;31 unmodified lines41 ///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.44-pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) -> ExitCode {45+pub 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 lines132 exit_code133 }134 135 fn 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 lines285 }286 }287 288 fn 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