Skip to content

Commit

Permalink
FilePatcher: return None when num_replacements is 0
Browse files Browse the repository at this point in the history
Fix #102
  • Loading branch information
dmerejkowsky committed Sep 9, 2023
1 parent 0622302 commit c446b98
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/file_patcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pub struct FilePatcher {
}

impl FilePatcher {
/// Try and build a `FilePatcher` for the given path and query
/// Return Ok(None) if there is nothing to replace in the file
pub fn new(console: &Console, path: &Path, query: &Query) -> Result<Option<FilePatcher>> {
let mut num_replacements = 0;
let mut num_lines = 0;
Expand Down Expand Up @@ -62,12 +64,16 @@ impl FilePatcher {
}
}
}
Ok(Some(FilePatcher {
path: path.to_path_buf(),
new_contents,
num_lines,
num_replacements,
}))
if num_replacements == 0 {
Ok(None)
} else {
Ok(Some(FilePatcher {
path: path.to_path_buf(),
new_contents,
num_lines,
num_replacements,
}))
}
}

pub(crate) fn num_replacements(&self) -> usize {
Expand Down

0 comments on commit c446b98

Please sign in to comment.