peace_rt/cmds/
states_current_stored_display_cmd.rs1use std::{fmt::Debug, marker::PhantomData};
2
3use peace_cmd_ctx::{CmdCtxSpsf, CmdCtxTypes};
4use peace_cmd_model::CmdOutcome;
5use peace_resource_rt::states::StatesCurrentStored;
6use peace_rt_model_core::output::OutputWrite;
7
8use crate::cmds::StatesCurrentReadCmd;
9
10#[derive(Debug)]
12pub struct StatesCurrentStoredDisplayCmd<CmdCtxTypesT>(PhantomData<CmdCtxTypesT>);
13
14#[cfg(not(feature = "error_reporting"))]
15impl<CmdCtxTypesT> StatesCurrentStoredDisplayCmd<CmdCtxTypesT>
16where
17 CmdCtxTypesT: CmdCtxTypes,
18{
19 pub async fn exec<'ctx>(
26 cmd_ctx: &mut CmdCtxSpsf<'ctx, CmdCtxTypesT>,
27 ) -> Result<
28 CmdOutcome<StatesCurrentStored, <CmdCtxTypesT as CmdCtxTypes>::AppError>,
29 <CmdCtxTypesT as CmdCtxTypes>::AppError,
30 >
31 where
32 CmdCtxTypesT: 'ctx,
33 {
34 let states_current_stored_result = StatesCurrentReadCmd::exec(cmd_ctx).await;
35 let output = cmd_ctx.output_mut();
36
37 match states_current_stored_result {
38 Ok(states_current_cmd_outcome) => {
39 if let Some(states_current_stored) = states_current_cmd_outcome.value() {
40 output.present(states_current_stored).await?;
41 }
42 Ok(states_current_cmd_outcome)
43 }
44 Err(e) => {
45 output.write_err(&e).await?;
46 Err(e)
47 }
48 }
49 }
50}
51
52#[cfg(feature = "error_reporting")]
54impl<CmdCtxTypesT> StatesCurrentStoredDisplayCmd<CmdCtxTypesT>
55where
56 CmdCtxTypesT: CmdCtxTypes,
57 <CmdCtxTypesT as CmdCtxTypes>::AppError: miette::Diagnostic,
58{
59 pub async fn exec<'ctx>(
66 cmd_ctx: &mut CmdCtxSpsf<'ctx, CmdCtxTypesT>,
67 ) -> Result<
68 CmdOutcome<StatesCurrentStored, <CmdCtxTypesT as CmdCtxTypes>::AppError>,
69 <CmdCtxTypesT as CmdCtxTypes>::AppError,
70 >
71 where
72 CmdCtxTypesT: 'ctx,
73 {
74 let states_current_stored_result = StatesCurrentReadCmd::exec(cmd_ctx).await;
75 let output = cmd_ctx.output_mut();
76
77 match states_current_stored_result {
78 Ok(states_current_cmd_outcome) => {
79 if let Some(states_current_stored) = states_current_cmd_outcome.value() {
80 output.present(states_current_stored).await?;
81 }
82 Ok(states_current_cmd_outcome)
83 }
84 Err(e) => {
85 output.write_err(&e).await?;
86 Err(e)
87 }
88 }
89 }
90}
91
92impl<CmdCtxTypesT> Default for StatesCurrentStoredDisplayCmd<CmdCtxTypesT> {
93 fn default() -> Self {
94 Self(PhantomData)
95 }
96}