docker_wrapper/command/swarm/
unlock.rs

1//! Docker swarm unlock command implementation.
2
3use crate::command::{CommandExecutor, DockerCommand};
4use crate::error::Result;
5use async_trait::async_trait;
6
7/// Result of swarm unlock command
8#[derive(Debug, Clone)]
9pub struct SwarmUnlockResult {
10    /// Whether the unlock was successful
11    pub success: bool,
12    /// Raw output from the command
13    pub output: String,
14}
15
16/// Docker swarm unlock command builder
17///
18/// Unlock a locked swarm manager node.
19#[derive(Debug, Clone, Default)]
20pub struct SwarmUnlockCommand {
21    /// Command executor
22    pub executor: CommandExecutor,
23}
24
25impl SwarmUnlockCommand {
26    /// Create a new swarm unlock command
27    #[must_use]
28    pub fn new() -> Self {
29        Self::default()
30    }
31
32    /// Build the command arguments
33    fn build_args(&self) -> Vec<String> {
34        let mut args = vec!["swarm".to_string(), "unlock".to_string()];
35        args.extend(self.executor.raw_args.clone());
36        args
37    }
38}
39
40#[async_trait]
41impl DockerCommand for SwarmUnlockCommand {
42    type Output = SwarmUnlockResult;
43
44    fn get_executor(&self) -> &CommandExecutor {
45        &self.executor
46    }
47
48    fn get_executor_mut(&mut self) -> &mut CommandExecutor {
49        &mut self.executor
50    }
51
52    fn build_command_args(&self) -> Vec<String> {
53        self.build_args()
54    }
55
56    async fn execute(&self) -> Result<Self::Output> {
57        let args = self.build_args();
58        let output = self.execute_command(args).await?;
59        Ok(SwarmUnlockResult {
60            success: true,
61            output: output.stdout,
62        })
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69
70    #[test]
71    fn test_swarm_unlock_basic() {
72        let cmd = SwarmUnlockCommand::new();
73        let args = cmd.build_args();
74        assert_eq!(args, vec!["swarm", "unlock"]);
75    }
76}