feat: custom command builder

Implemented custom command builder with nicer api suited for my needs.
Also returned error if there are no containers in
`scripts::postgres::get_containers`.
This commit is contained in:
2023-06-02 17:18:25 +02:00
parent e3306c494d
commit 316b37cd05
7 changed files with 132 additions and 87 deletions

View File

@@ -1,13 +1,14 @@
use super::DockerCommand;
use anyhow::Result;
use crate::command_builder::CommandBuilder;
// simple commands
pub fn build() -> Result<()> {
DockerCommand::docker_compose().args("build").spawn_wait()
CommandBuilder::docker_compose().args("build").exec()
}
pub fn down() -> Result<()> {
DockerCommand::docker_compose().args("down").spawn_wait()
CommandBuilder::docker_compose().args("down").exec()
}
/// Start containers via `docker compose start`. Optionally pass containers to be started.
@@ -18,25 +19,25 @@ pub fn down() -> Result<()> {
/// `docker compose --env-file ./.env -f docker/local/docker-compose.yaml up start`
pub fn start(containers: Option<&str>) -> Result<()> {
let args = format!("start {}", containers.unwrap_or(""));
DockerCommand::docker_compose().args("start").spawn_wait()
CommandBuilder::docker_compose().args("start").exec()
}
pub fn stop() -> Result<()> {
DockerCommand::docker_compose().args("stop").spawn_wait()
CommandBuilder::docker_compose().args("stop").exec()
}
pub fn up() -> Result<()> {
DockerCommand::docker_compose().args("up -d").spawn_wait()
CommandBuilder::docker_compose().args("up -d").exec()
}
// shortcuts
pub fn rebuild() -> Result<()> {
stop()?;
build()?;
start(None)
up()
}
pub fn restart() -> Result<()> {
stop()?;
start(None)
up()
}