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+ } ;
58use 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 ) ]
1114pub 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 ) ]
3033pub 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
3740impl 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 {
8083impl 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
107113impl 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