compose_rs/command/
mod.rs1use std::{io, process::Output};
2
3use crate::ComposeError;
4mod up;
5pub use up::UpCommand;
6mod down;
7pub use down::DownCommand;
8mod ps;
9pub use ps::PsCommand;
10mod scale;
11pub use scale::ScaleCommand;
12pub mod stats;
13pub use stats::StatsCommand;
14pub mod start;
15pub use start::StartCommand;
16
17pub trait ComposeCommand<ReturnT, ArgType = ()>
18where
19 ArgType: ComposeCommandArgs,
20{
21 const COMMAND: &'static str;
22
23 fn exec(self) -> Result<ReturnT, ComposeError>;
24}
25
26pub trait ComposeCommandArgs {
27 fn args(&self) -> Vec<String>;
28}
29
30impl ComposeCommandArgs for () {
31 fn args(&self) -> Vec<String> {
32 Vec::new()
33 }
34}
35
36pub(super) trait CatchOutput {
37 fn catch_output(self) -> Result<Output, ComposeError>;
38}
39
40impl CatchOutput for io::Result<Output> {
41 fn catch_output(self) -> Result<Output, ComposeError> {
42 match self {
43 Ok(output) => {
44 if output.status.success() {
45 Ok(output)
46 } else {
47 Err(ComposeError::CommandFailed(output))
48 }
49 }
50 Err(err) => Err(ComposeError::IoError(err)),
51 }
52 }
53}