Skip to content

Commit c76debc

Browse files
fix: use self.execute_command to avoid docker docker bug (#180)
* fix: use self.execute_command to avoid docker docker bug Commands were incorrectly calling self.executor.execute_command("docker", args) which resulted in 'docker docker <cmd>' being executed. This fixes all 10 affected commands to use self.execute_command(args) instead. Also adds a CI check to prevent this antipattern from reoccurring. Fixes #176 * fix: address clippy unnecessary_unwrap warnings in tests --------- Co-authored-by: KrLite <wang070621@foxmail.com>
1 parent 3576dce commit c76debc

12 files changed

Lines changed: 36 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ jobs:
4646
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'
4747
run: cargo fmt -- --check
4848

49+
- name: Check for executor.execute_command antipattern
50+
if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest'
51+
run: |
52+
# Commands should use self.execute_command(args) not self.executor.execute_command("docker", args)
53+
# The latter causes "docker docker <cmd>" double-command bug
54+
if grep -r 'executor\.execute_command("docker"' src/command/; then
55+
echo "ERROR: Found executor.execute_command(\"docker\", ...) antipattern!"
56+
echo "Use self.execute_command(args) instead to avoid 'docker docker' bug."
57+
exit 1
58+
fi
59+
4960
- name: Run Clippy
5061
if: matrix.rust == 'stable'
5162
run: cargo clippy --all-targets --all-features -- -D warnings

src/command/build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ impl BuildCommand {
10341034
&self.executor
10351035
}
10361036

1037-
/// Get a mutable reference to the command executor
1037+
/// Get a mutable reference to the command executor
10381038
#[must_use]
10391039
pub fn get_executor_mut(&mut self) -> &mut CommandExecutor {
10401040
&mut self.executor
@@ -1322,7 +1322,7 @@ impl DockerCommand for BuildCommand {
13221322

13231323
async fn execute(&self) -> Result<Self::Output> {
13241324
let args = self.build_command_args();
1325-
let output = self.executor.execute_command("docker", args).await?;
1325+
let output = self.execute_command(args).await?;
13261326

13271327
// Extract image ID from output
13281328
let image_id = if self.quiet {

src/command/builder/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl DockerCommand for BuilderBuildCommand {
165165
async fn execute(&self) -> Result<Self::Output> {
166166
// The builder build command has the same output as regular build
167167
let args = self.build_command_args();
168-
let output = self.inner.executor.execute_command("docker", args).await?;
168+
let output = self.execute_command(args).await?;
169169

170170
// Extract image ID from output
171171
let image_id = extract_image_id(&output.stdout);

src/command/builder/prune.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl DockerCommand for BuilderPruneCommand {
191191

192192
async fn execute(&self) -> Result<Self::Output> {
193193
let args = self.build_command_args();
194-
let output = self.executor.execute_command("docker", args).await?;
194+
let output = self.execute_command(args).await?;
195195

196196
let (deleted_cache_ids, space_reclaimed, space_reclaimed_str) =
197197
Self::parse_output(&output.stdout);

src/command/images.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ impl DockerCommand for ImagesCommand {
820820

821821
async fn execute(&self) -> Result<Self::Output> {
822822
let args = self.build_command_args();
823-
let output = self.executor.execute_command("docker", args).await?;
823+
let output = self.execute_command(args).await?;
824824

825825
let images = self.parse_output(&output);
826826

src/command/login.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl DockerCommand for LoginCommand {
234234

235235
async fn execute(&self) -> Result<Self::Output> {
236236
let args = self.build_command_args();
237-
let output = self.executor.execute_command("docker", args).await?;
237+
let output = self.execute_command(args).await?;
238238

239239
Ok(LoginOutput { output })
240240
}

src/command/logout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl DockerCommand for LogoutCommand {
186186

187187
async fn execute(&self) -> Result<Self::Output> {
188188
let args = self.build_command_args();
189-
let output = self.executor.execute_command("docker", args).await?;
189+
let output = self.execute_command(args).await?;
190190

191191
Ok(LogoutOutput { output })
192192
}

src/command/pull.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ impl DockerCommand for PullCommand {
349349

350350
async fn execute(&self) -> Result<Self::Output> {
351351
let args = self.build_command_args();
352-
self.executor.execute_command("docker", args).await
352+
self.execute_command(args).await
353353
}
354354
}
355355

src/command/push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ impl DockerCommand for PushCommand {
357357

358358
async fn execute(&self) -> Result<Self::Output> {
359359
let args = self.build_command_args();
360-
self.executor.execute_command("docker", args).await
360+
self.execute_command(args).await
361361
}
362362
}
363363

src/command/search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl DockerCommand for SearchCommand {
488488

489489
async fn execute(&self) -> Result<Self::Output> {
490490
let args = self.build_command_args();
491-
let output = self.executor.execute_command("docker", args).await?;
491+
let output = self.execute_command(args).await?;
492492

493493
let repositories = self.parse_output(&output)?;
494494

0 commit comments

Comments
 (0)