diff --git a/src/main.rs b/src/main.rs index 97c2ceb05..3836fea9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use atty::Stream; use clap::{CommandFactory, Parser}; use globset::GlobBuilder; use lscolors::LsColors; -use regex::bytes::{RegexBuilder, RegexSetBuilder}; +use regex::bytes::{RegexBuilder, RegexSetBuilder, Regex}; use crate::cli::{ColorWhen, Opts}; use crate::config::Config; @@ -84,35 +84,24 @@ fn run() -> Result { let pattern = &opts.pattern; let exprs = &opts.exprs; let empty = Vec::new(); - let patterns = exprs + + let pattern_regexps = exprs .as_ref() .unwrap_or(&empty) - .into_iter() - .chain(vec![pattern]) - .collect::>(); - let pattern_regexps = patterns .iter() - .map(|pat| { - let re = build_pattern_regex(pat, &opts); - match re { - Ok(r) => r, - Err(e) => panic!("Bad pattern: {}", e), - } - }) - .collect::>(); + .chain([pattern]) + .map(|pat| { build_pattern_regex(pat, &opts) }) + .collect::>>()?; let config = construct_config(opts, &pattern_regexps)?; + ensure_use_hidden_option_for_leading_dot_pattern(&config, &pattern_regexps)?; + let regexps = pattern_regexps .iter() - .map(|pat| { - let regex = build_regex(pat.to_string(), &config); - match regex { - Ok(r) => r, - Err(e) => panic!("Bad regex: {}", e), - } - }) - .collect(); + .map(|pat| { build_regex(pat.to_string(), &config) }) + .collect::>>()?; + walk::scan(&search_paths, Arc::new(regexps), Arc::new(config)) } @@ -192,7 +181,7 @@ fn check_path_separator_length(path_separator: Option<&str>) -> Result<()> { } } -fn construct_config(mut opts: Opts, pattern_regexps: &Vec) -> Result { +fn construct_config(mut opts: Opts, pattern_regexps: &[String]) -> Result { // 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 = !opts.ignore_case @@ -438,7 +427,7 @@ fn extract_time_constraints(opts: &Opts) -> Result> { fn ensure_use_hidden_option_for_leading_dot_pattern( config: &Config, - pattern_regexps: &Vec, + pattern_regexps: &[String], ) -> Result<()> { if cfg!(unix) && config.ignore_hidden