compose_rs/command/
start.rs1use crate::{ComposeCommand, ComposeError};
2
3use super::{CatchOutput, ComposeCommandArgs};
4
5pub enum StartArgs {
6 DryRun,
8}
9
10impl ComposeCommandArgs for StartArgs {
11 fn args(&self) -> Vec<String> {
12 match self {
13 StartArgs::DryRun => vec!["--dry-run".to_string()],
14 }
15 }
16}
17
18pub struct StartCommand {
19 command: std::process::Command,
20 args: Vec<StartArgs>,
21}
22
23impl StartCommand {
24 pub fn new(command: std::process::Command) -> Self {
25 Self {
26 command,
27 args: Vec::new(),
28 }
29 }
30
31 pub fn dry_run(mut self) -> Self {
32 self.args.push(StartArgs::DryRun);
33 self
34 }
35}
36
37impl ComposeCommand<(), StartArgs> for StartCommand {
38 const COMMAND: &'static str = "start";
39
40 fn exec(self) -> Result<(), ComposeError> {
41 let mut command = self.command;
42 command.arg(Self::COMMAND);
43
44 for arg in self.args {
45 command.args(&arg.args());
46 }
47
48 command.output().catch_output()?;
49
50 Ok(())
51 }
52}