docker_wrapper/command/builder/
stop.rs1use crate::command::{CommandExecutor, CommandOutput, DockerCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7#[derive(Debug, Clone)]
9pub struct BuildxStopResult {
10 pub name: Option<String>,
12 pub output: String,
14 pub success: bool,
16}
17
18impl BuildxStopResult {
19 fn parse(name: Option<&str>, output: &CommandOutput) -> Self {
21 Self {
22 name: name.map(ToString::to_string),
23 output: output.stdout.clone(),
24 success: output.success,
25 }
26 }
27}
28
29#[derive(Debug, Clone, Default)]
52pub struct BuildxStopCommand {
53 name: Option<String>,
55 pub executor: CommandExecutor,
57}
58
59impl BuildxStopCommand {
60 #[must_use]
62 pub fn new() -> Self {
63 Self::default()
64 }
65
66 #[must_use]
68 pub fn name(mut self, name: impl Into<String>) -> Self {
69 self.name = Some(name.into());
70 self
71 }
72
73 fn build_args(&self) -> Vec<String> {
75 let mut args = vec!["buildx".to_string(), "stop".to_string()];
76
77 if let Some(ref name) = self.name {
78 args.push(name.clone());
79 }
80
81 args.extend(self.executor.raw_args.clone());
82
83 args
84 }
85}
86
87#[async_trait]
88impl DockerCommand for BuildxStopCommand {
89 type Output = BuildxStopResult;
90
91 fn get_executor(&self) -> &CommandExecutor {
92 &self.executor
93 }
94
95 fn get_executor_mut(&mut self) -> &mut CommandExecutor {
96 &mut self.executor
97 }
98
99 fn build_command_args(&self) -> Vec<String> {
100 self.build_args()
101 }
102
103 async fn execute(&self) -> Result<Self::Output> {
104 let args = self.build_args();
105 let output = self.execute_command(args).await?;
106 Ok(BuildxStopResult::parse(self.name.as_deref(), &output))
107 }
108}
109
110#[cfg(test)]
111mod tests {
112 use super::*;
113
114 #[test]
115 fn test_buildx_stop_basic() {
116 let cmd = BuildxStopCommand::new();
117 let args = cmd.build_args();
118 assert_eq!(args, vec!["buildx", "stop"]);
119 }
120
121 #[test]
122 fn test_buildx_stop_with_name() {
123 let cmd = BuildxStopCommand::new().name("mybuilder");
124 let args = cmd.build_args();
125 assert!(args.contains(&"mybuilder".to_string()));
126 }
127}