Skip to main content

dry4rust/cli/
stats_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;
7
8use crate::analysis::AnalysisResult;
9use crate::cli::cli_error::CliResult;
10use crate::output::reporter::Reporter;
11
12/// `stats`: the summary and nothing else.
13pub struct StatsCommand<'a> {
14    result: &'a AnalysisResult,
15    reporter: &'a dyn Reporter,
16}
17
18impl<'a> StatsCommand<'a> {
19    #[must_use]
20    pub const fn new(result: &'a AnalysisResult, reporter: &'a dyn Reporter) -> Self {
21        Self { result, reporter }
22    }
23
24    /// Write the duplication summary.
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        self.reporter.report_stats(&self.result.stats, writer)?;
31        Ok(())
32    }
33}