feat: finish docker cli

Implement wanted functionality for docker subcommands.
This commit is contained in:
Matej Janezic 2023-05-23 21:48:29 +02:00
parent 9c34f6ff59
commit 907740fc5a
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
2 changed files with 10 additions and 6 deletions

View File

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

View File

@ -34,12 +34,12 @@ impl DockerCommand {
self
}
fn stdout(mut self) -> Result<String> {
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(())
}
}