feat: finish docker compose cli

Implemented basic wanted functionality for docker compose subcommands.
We currently assume that docker-compose.yaml file is located in
local/docker/ folder.
This commit is contained in:
2023-05-21 23:41:15 +02:00
parent 83c3b05d30
commit 4762c991a3
5 changed files with 77 additions and 13 deletions

View File

@@ -2,3 +2,44 @@ pub mod django;
pub mod docker;
pub mod docker_compose;
pub mod postgres;
use std::{ffi::OsStr, process::Command};
use anyhow::{Context, Result};
struct DockerCommand {
command: Command,
}
impl DockerCommand {
fn new<T>(program: T) -> Self
where
T: AsRef<OsStr>,
{
DockerCommand {
command: Command::new(program),
}
}
fn docker() -> Self {
Self::new("docker")
}
fn docker_compose() -> Self {
Self::new("docker").args("compose -f docker/local/docker-compose.yaml")
}
fn args(mut self, args: &str) -> Self {
self.command.args(args.split_whitespace());
self
}
fn spawn_wait(mut self) -> Result<()> {
self.command
.spawn()
.context("failed spawning command")?
.wait()
.context("failed while waiting")?;
Ok(())
}
}