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 crate::analysis::AnalysisResult;
7use crate::cli::cli_error::CliResult;
8use crate::cli::command_outcome::CommandOutcome;
9use crate::output::reporter::Reporter;
10
11/// `stats`: the summary and nothing else.
12pub struct StatsCommand<'a> {
13    result: &'a AnalysisResult,
14    reporter: &'a dyn Reporter,
15}
16
17impl<'a> StatsCommand<'a> {
18    #[must_use]
19    pub const fn new(result: &'a AnalysisResult, reporter: &'a dyn Reporter) -> Self {
20        Self { result, reporter }
21    }
22
23    /// Build the duplication summary.
24    ///
25    /// # Errors
26    ///
27    /// Returns [`crate::cli::cli_error::CliError::Io`] if the reporter fails.
28    pub fn run(&self) -> CliResult<CommandOutcome> {
29        let text = self.reporter.report_stats(&self.result.stats)?;
30        Ok(CommandOutcome::succeeded(text))
31    }
32}