dry4rust/cli/command_outcome.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::cli::cli_error::CliResult;
7
8/// What a command produced: the text it means to print, and the verdict that
9/// decides the exit code once that text has reached stdout.
10///
11/// Keeping the two together lets `check` write its report and still fail: the
12/// text and the [`crate::cli::cli_error::CliError::CheckFailed`] both travel up
13/// to the one place that prints and then exits.
14pub struct CommandOutcome {
15 pub text: String,
16 pub result: CliResult,
17}
18
19impl CommandOutcome {
20 #[must_use]
21 pub const fn new(text: String, result: CliResult) -> Self {
22 Self { text, result }
23 }
24
25 #[must_use]
26 pub const fn succeeded(text: String) -> Self {
27 Self {
28 text,
29 result: Ok(()),
30 }
31 }
32}