refactor: remove pattern from matches as it's not needed on each
instance
This commit is contained in:
parent
ea6c75a0a8
commit
de79955778
3 changed files with 6 additions and 5 deletions
|
|
@ -27,6 +27,9 @@ fn run() -> anyhow::Result<Matches> {
|
||||||
// println!("{:?} {}", cli.file_paths, cli.pattern);
|
// println!("{:?} {}", cli.file_paths, cli.pattern);
|
||||||
|
|
||||||
let matches = process_files(&cli.file_paths, &cli.pattern, &cli.get_options())?;
|
let matches = process_files(&cli.file_paths, &cli.pattern, &cli.get_options())?;
|
||||||
|
if !matches.is_empty() {
|
||||||
|
println!("Matches for pattern {}:", cli.pattern);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(matches)
|
Ok(matches)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ pub struct Match {
|
||||||
|
|
||||||
pub struct Matches {
|
pub struct Matches {
|
||||||
pub items: Vec<Match>,
|
pub items: Vec<Match>,
|
||||||
pub pattern: String,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Matches {
|
impl Matches {
|
||||||
|
|
@ -29,8 +28,6 @@ impl Display for Match {
|
||||||
|
|
||||||
impl Display for Matches {
|
impl Display for Matches {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
writeln!(f, "Matches for pattern {}:", self.pattern)?;
|
|
||||||
|
|
||||||
for (idx, item) in self.items.iter().enumerate() {
|
for (idx, item) in self.items.iter().enumerate() {
|
||||||
if idx > 0 {
|
if idx > 0 {
|
||||||
writeln!(f)?;
|
writeln!(f)?;
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,9 @@ pub fn process_files(
|
||||||
.build()
|
.build()
|
||||||
.with_context(|| format!("invalid regex: {:?}", pattern))?;
|
.with_context(|| format!("invalid regex: {:?}", pattern))?;
|
||||||
|
|
||||||
let mut matches = Matches { items: vec![], pattern: String::from(pattern) };
|
let mut matches = Matches { items: vec![] };
|
||||||
|
|
||||||
|
// fails and stops everything when one file fails
|
||||||
for file_path in file_paths {
|
for file_path in file_paths {
|
||||||
let lines_iter = read_lines(file_path)?;
|
let lines_iter = read_lines(file_path)?;
|
||||||
let mut _matches = match_pattern(lines_iter, pattern, file_path, ®)?;
|
let mut _matches = match_pattern(lines_iter, pattern, file_path, ®)?;
|
||||||
|
|
@ -71,7 +72,7 @@ pub fn match_pattern(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Matches { items: matches, pattern: String::from(pattern) })
|
Ok(Matches { items: matches })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue