Skip to main content

dry4rust/cli/
ignored_command.rs

1// Copyright (c) 2026 Matjaz Domen Pecan
2// Copyright 2026 Umberto Gotti <umberto.gotti@umbertogotti.dev>
3// Licensed under the MIT License
4// SPDX-License-Identifier: MIT
5
6use std::io::Write;
7use std::path::Path;
8
9use crate::cli::cli_error::CliResult;
10use crate::cli::ignore_entry_line::IgnoreEntryLine;
11use crate::suppression::ignore_file::IgnoreFile;
12
13/// `ignored`: list what the ignore file holds.
14pub struct IgnoredCommand<'a> {
15    root: &'a Path,
16}
17
18impl<'a> IgnoredCommand<'a> {
19    #[must_use]
20    pub const fn new(root: &'a Path) -> Self {
21        Self { root }
22    }
23
24    /// Write every ignore entry, or say there are none.
25    ///
26    /// # Errors
27    ///
28    /// Returns [`crate::cli::cli_error::CliError::Io`] if the writer fails.
29    pub fn run(&self, writer: &mut impl Write) -> CliResult {
30        let ignore_file = IgnoreFile::load(self.root);
31        if ignore_file.ignore.is_empty() {
32            writeln!(writer, "No ignored fingerprints.")?;
33            return Ok(());
34        }
35        writeln!(writer, "Ignored fingerprints:")?;
36        for entry in &ignore_file.ignore {
37            writeln!(writer, "{}", IgnoreEntryLine::new(entry))?;
38        }
39        Ok(())
40    }
41}