Skip to content
Myr

feat: Add --exact argument to match exact filename

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

authored by DeflateAwning · committed by DeflateAwning · parent 0e74d5b · Browse files · 2 files+19 added−2 removed
This commit

State

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

Diff stats

2 files+19 added−2 removed

  • other:+19 added−2 removed

2 files+19 added−2 removed

modified:src/cli.rs+15 added-2 removed
171 unmodified lines
172 pub regex: bool,173174 /// Treat the pattern as a literal string instead of a regular expression. Note175 /// that this also performs substring comparison. If you want to match on an176 /// exact filename, consider using '--glob'.176 /// exact filename, consider using '--glob' or '--exact' instead.177 #[arg(178 long,179 short = 'F',180 alias = "literal",181 hide_short_help = true,182 help = "Treat pattern as literal string stead of regex",182 help = "Treat pattern as literal string instead of regex",183 long_help184 )]185 pub fixed_strings: bool,186187 /// Perform an exact match. This is equivalent to '--fixed-strings' but requires188 /// the pattern to match the entire filename (or path if '--full-path' is used),189 /// rather than a substring. Special regex characters in the pattern are treated190 /// as literal characters.191 #[arg(192 long,193 conflicts_with("glob"),194 hide_short_help = true,195 help = "Match the entire filename exactly (literal, non-substring)",196 long_help197 )]198 pub exact: bool,199200 /// Add additional required search patterns, all of which must be matched. Multiple201 /// additional patterns can be specified. The patterns are regular202 /// expressions, unless '--glob' or '--fixed-strings' is used.203 #[arg(
763 unmodified lines
modified:src/main.rs+4 added
168 unmodified lines
169fn build_pattern_regex(pattern: &str, opts: &Opts) -> Result<String> {170 Ok(if opts.glob && !pattern.is_empty() {171 let glob = GlobBuilder::new(pattern).literal_separator(true).build()?;172 glob.regex().to_owned()173 } else if opts.exact {174 // Anchor the escaped pattern so the full filename (or path) must match exactly.175 // Literal. No substring matching.176 format!("^{}$", regex::escape(pattern))177 } else if opts.fixed_strings {178 // Treat pattern as literal string if '--fixed-strings' is used179 regex::escape(pattern)180 } else {
325 unmodified lines