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;
14
15pub trait ComposeCommand<ReturnT, ArgType = ()>
16where
17 ArgType: ComposeCommandArgs,
18{
19 const COMMAND: &'static str;
20
21 fn exec(self) -> Result<ReturnT, ComposeError>;
22}
23
24pub trait ComposeCommandArgs {
25 fn args(&self) -> Vec<String>;
26}
27
28impl ComposeCommandArgs for () {
29 fn args(&self) -> Vec<String> {
30 Vec::new()
31 }
32}
33
34pub(super) trait CatchOutput {
35 fn catch_output(self) -> Result<Output, ComposeError>;
36}
37
38impl CatchOutput for io::Result<Output> {
39 fn catch_output(self) -> Result<Output, ComposeError> {
40 match self {
41 Ok(output) => {
42 if output.status.success() {
43 Ok(output)
44 } else {
45 Err(ComposeError::CommandFailed(output))
46 }
47 }
48 Err(err) => Err(ComposeError::IoError(err)),
49 }
50 }
51}