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::fmt::Write as _;
7use std::path::Path;
8
9use crate::cli::cli_error::CliResult;
10use crate::cli::command_outcome::CommandOutcome;
11use crate::cli::ignore_entry_line::IgnoreEntryLine;
12use crate::suppression::ignore_file::IgnoreFile;
13
14/// `ignored`: list what the ignore file holds.
15pub struct IgnoredCommand<'a> {
16    root: &'a Path,
17}
18
19impl<'a> IgnoredCommand<'a> {
20    #[must_use]
21    pub const fn new(root: &'a Path) -> Self {
22        Self { root }
23    }
24
25    /// Build every ignore entry, or say there are none.
26    ///
27    /// # Errors
28    ///
29    /// Never fails; the signature matches its siblings so the dispatcher can
30    /// treat every command alike.
31    pub fn run(&self) -> CliResult<CommandOutcome> {
32        let ignore_file = IgnoreFile::load(self.root);
33        let mut out = String::new();
34        if ignore_file.ignore.is_empty() {
35            let _ = writeln!(out, "No ignored fingerprints.");
36            return Ok(CommandOutcome::succeeded(out));
37        }
38        let _ = writeln!(out, "Ignored fingerprints:");
39        for entry in &ignore_file.ignore {
40            let _ = writeln!(out, "{}", IgnoreEntryLine::new(entry));
41        }
42        Ok(CommandOutcome::succeeded(out))
43    }
44}