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(()) } }