Skip to content

Commit 796fb6a

Browse files
committed
feat: compose commands
1 parent 053dacc commit 796fb6a

35 files changed

Lines changed: 1254 additions & 1067 deletions

examples/docker_compose.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
//! Docker Compose example demonstrating multi-container application management
1+
//! Docker Compose example demonstrating multi-container application management.
22
//!
33
//! This example shows how to use the compose feature to manage
44
//! multi-container applications with Docker Compose.
55
//!
6-
//! Run with: cargo run --example docker_compose --features compose
6+
//! Run with: cargo run --example docker_compose --features compose.
77
88
#[cfg(feature = "compose")]
99
use docker_wrapper::compose::down::RemoveImages;

examples/exec_examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ async fn env_exec_example(container_id: &str) {
175175
}
176176
}
177177

178-
// Multiple environment variables from HashMap
178+
// multiple environment variables from HashMap
179179
let mut env_vars = HashMap::new();
180180
env_vars.insert("DEBUG".to_string(), "true".to_string());
181181
env_vars.insert("LOG_LEVEL".to_string(), "info".to_string());

src/command.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,10 @@ pub trait DockerCommand {
124124
}
125125

126126
/// Progress output type for compose commands.
127-
#[derive(Debug, Clone, Copy)]
127+
#[derive(Debug, Default, Clone, Copy)]
128128
pub enum ProgressType {
129129
/// Auto-detects progress output.
130+
#[default]
130131
Auto,
131132
/// TTY output.
132133
Tty,
@@ -151,13 +152,14 @@ impl std::fmt::Display for ProgressType {
151152
}
152153

153154
/// ANSI control character mode.
154-
#[derive(Debug, Clone, Copy)]
155+
#[derive(Debug, Default, Clone, Copy)]
155156
pub enum AnsiMode {
156157
/// Never prints ANSI.
157158
Never,
158159
/// Always prints ANSI.
159160
Always,
160161
/// Auto-detects ANSI.
162+
#[default]
161163
Auto,
162164
}
163165

src/command/bake.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl BakeCommand {
171171

172172
/// Add a target to build
173173
///
174-
/// Multiple targets can be specified. If no targets are specified,
174+
/// multiple targets can be specified. If no targets are specified,
175175
/// all targets defined in the bake file will be built.
176176
///
177177
/// # Examples
@@ -941,9 +941,7 @@ mod tests {
941941
fn test_bake_command_extensibility() {
942942
let mut bake_cmd = BakeCommand::new();
943943
bake_cmd.executor_mut().add_arg("--experimental");
944-
bake_cmd
945-
.executor_mut()
946-
.add_args(vec!["--custom", "value"]);
944+
bake_cmd.executor_mut().add_args(vec!["--custom", "value"]);
947945

948946
// Extensibility is handled through the executor's raw_args
949947
// The actual testing of raw args is done in command.rs tests

src/command/compose/attach.rs

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
11
//! Docker Compose attach command implementation using unified trait pattern.
22
3-
use super::{CommandExecutor, ComposeCommand, ComposeConfig, DockerCommand};
4-
use crate::error::Result;
3+
use crate::{
4+
compose::{ComposeCommand, ComposeConfig},
5+
error::Result,
6+
CommandExecutor, DockerCommand,
7+
};
58
use async_trait::async_trait;
69

7-
/// Docker Compose attach command
10+
/// Docker Compose attach command.
811
///
912
/// Attach to a running container's output.
1013
#[derive(Debug, Clone, Default)]
1114
pub struct ComposeAttachCommand {
12-
/// Base command executor
15+
/// Base command executor.
1316
pub executor: CommandExecutor,
14-
/// Base compose configuration
17+
/// Base compose configuration.
1518
pub config: ComposeConfig,
16-
/// Service to attach to
19+
/// Service to attach to.
1720
pub service: String,
18-
/// Detach keys sequence
21+
/// Detach keys sequence.
1922
pub detach_keys: Option<String>,
20-
/// Container index if service has multiple instances
23+
/// Container index if service has multiple instances.
2124
pub index: Option<u32>,
22-
/// Don't stream STDIN
25+
/// Doesn't stream STDIN.
2326
pub no_stdin: bool,
24-
/// Use a pseudo-TTY
27+
/// Uses a pseudo-TTY.
2528
pub sig_proxy: bool,
2629
}
2730

28-
/// Result from attach command
31+
/// Result from attach command.
2932
#[derive(Debug, Clone)]
3033
pub struct AttachResult {
31-
/// Output from the command
34+
/// Output from the command.
3235
pub output: String,
33-
/// Whether the operation succeeded
36+
/// Whether the operation succeeded.
3437
pub success: bool,
3538
}
3639

3740
impl ComposeAttachCommand {
38-
/// Create a new attach command
41+
/// Creates a new attach command.
3942
#[must_use]
4043
pub fn new(service: impl Into<String>) -> Self {
4144
Self {
@@ -47,28 +50,28 @@ impl ComposeAttachCommand {
4750
}
4851
}
4952

50-
/// Set detach keys
53+
/// Sets detach keys.
5154
#[must_use]
5255
pub fn detach_keys(mut self, keys: impl Into<String>) -> Self {
5356
self.detach_keys = Some(keys.into());
5457
self
5558
}
5659

57-
/// Set container index
60+
/// Sets container index.
5861
#[must_use]
5962
pub fn index(mut self, index: u32) -> Self {
6063
self.index = Some(index);
6164
self
6265
}
6366

64-
/// Don't attach to STDIN
67+
/// Doesn't attach to STDIN.
6568
#[must_use]
6669
pub fn no_stdin(mut self) -> Self {
6770
self.no_stdin = true;
6871
self
6972
}
7073

71-
/// Disable signal proxy
74+
/// Disables signal proxy.
7275
#[must_use]
7376
pub fn no_sig_proxy(mut self) -> Self {
7477
self.sig_proxy = false;
@@ -80,6 +83,10 @@ impl ComposeAttachCommand {
8083
impl DockerCommand for ComposeAttachCommand {
8184
type Output = AttachResult;
8285

86+
fn command_name() -> &'static str {
87+
<Self as ComposeCommand>::command_name()
88+
}
89+
8390
fn executor(&self) -> &CommandExecutor {
8491
&self.executor
8592
}
@@ -89,7 +96,6 @@ impl DockerCommand for ComposeAttachCommand {
8996
}
9097

9198
fn build_command_args(&self) -> Vec<String> {
92-
// Use the ComposeCommand implementation explicitly
9399
<Self as ComposeCommand>::build_command_args(self)
94100
}
95101

@@ -105,6 +111,10 @@ impl DockerCommand for ComposeAttachCommand {
105111
}
106112

107113
impl ComposeCommand for ComposeAttachCommand {
114+
fn subcommand_name() -> &'static str {
115+
"attach"
116+
}
117+
108118
fn config(&self) -> &ComposeConfig {
109119
&self.config
110120
}
@@ -113,14 +123,10 @@ impl ComposeCommand for ComposeAttachCommand {
113123
&mut self.config
114124
}
115125

116-
fn subcommand(&self) -> &'static str {
117-
"attach"
118-
}
119-
120126
fn build_subcommand_args(&self) -> Vec<String> {
121127
let mut args = Vec::new();
122128

123-
// Add flags
129+
// add flags
124130
if let Some(ref keys) = self.detach_keys {
125131
args.push("--detach-keys".to_string());
126132
args.push(keys.clone());

0 commit comments

Comments
 (0)