From 907740fc5a9a2cb84ff3a1195c0579ce3f78b3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Jane=C5=BEi=C4=8D?= Date: Tue, 23 May 2023 21:48:29 +0200 Subject: [PATCH] feat: finish docker cli Implement wanted functionality for docker subcommands. --- src/scripts/docker.rs | 6 +++++- src/scripts/mod.rs | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/scripts/docker.rs b/src/scripts/docker.rs index 4d4f5b9..ca9b53f 100644 --- a/src/scripts/docker.rs +++ b/src/scripts/docker.rs @@ -1,5 +1,9 @@ +use super::DockerCommand; use anyhow::Result; pub fn stop_all() -> Result<()> { - todo!() + let running_containers = DockerCommand::docker().args("ps -q").stdout()?; + DockerCommand::docker() + .args(&format!("stop {running_containers}")) + .spawn_wait() } diff --git a/src/scripts/mod.rs b/src/scripts/mod.rs index 1985547..fa98285 100644 --- a/src/scripts/mod.rs +++ b/src/scripts/mod.rs @@ -34,12 +34,12 @@ impl DockerCommand { self } + fn stdout(mut self) -> Result { + Ok(String::from_utf8(self.command.output()?.stdout)?) + } + fn spawn_wait(mut self) -> Result<()> { - self.command - .spawn() - .context("failed spawning command")? - .wait() - .context("failed while waiting")?; + self.command.spawn()?.wait()?; Ok(()) } }