dry4rust/cli/
ignore_command.rs1use std::io::Write;
7use std::path::Path;
8
9use crate::cli::cli_error::CliError;
10use crate::cli::cli_error::CliResult;
11use crate::fingerprint::Fingerprint;
12use crate::suppression::ignore_file::IgnoreFile;
13
14pub struct IgnoreCommand<'a> {
16 root: &'a Path,
17 fingerprint: &'a str,
18 reason: Option<&'a str>,
19}
20
21impl<'a> IgnoreCommand<'a> {
22 #[must_use]
23 pub const fn new(root: &'a Path, fingerprint: &'a str, reason: Option<&'a str>) -> Self {
24 Self {
25 root,
26 fingerprint,
27 reason,
28 }
29 }
30
31 pub fn run(&self, writer: &mut impl Write) -> CliResult {
39 let fingerprint = Fingerprint::from_hex(self.fingerprint)
40 .ok_or_else(|| CliError::InvalidFingerprint(self.fingerprint.to_owned()))?;
41 IgnoreFile::load(self.root)
42 .with_ignored(&fingerprint, self.reason.map(ToOwned::to_owned), vec![])
43 .save(self.root)?;
44 writeln!(writer, "Added {} to ignore list.", self.fingerprint)?;
45 Ok(())
46 }
47}