feat!: respect COMPOSE_FILE env and remove docker command
Read COMPOSE_FILE from env and use it if it is set. Default is still docker/local/docker-compose.yaml. BREAKING CHANGE: Removed docker subcommand. Added deprecation notice to compose subcommand.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use std::{
|
||||
collections::VecDeque,
|
||||
env,
|
||||
ffi::OsStr,
|
||||
fmt::Display,
|
||||
fs::{File, OpenOptions},
|
||||
@@ -27,10 +28,15 @@ impl From<&String> for Args {
|
||||
|
||||
impl From<&[String]> for Args {
|
||||
fn from(value: &[String]) -> Self {
|
||||
Self(Vec::from_iter(value.iter().map(|x| x.to_string())))
|
||||
Self(value.to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
fn get_compose_file() -> Result<String> {
|
||||
let cf = env::var("COMPOSE_FILE")?;
|
||||
Ok(cf)
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CommandBuilder {
|
||||
args: Vec<String>,
|
||||
@@ -52,7 +58,9 @@ impl CommandBuilder {
|
||||
}
|
||||
|
||||
pub fn docker_compose() -> Self {
|
||||
Self::default().args("docker compose -f docker/local/docker-compose.yaml")
|
||||
let cf =
|
||||
get_compose_file().unwrap_or_else(|_| "docker/local/docker-compose.yaml".to_string());
|
||||
Self::default().args("docker compose -f").args(&cf)
|
||||
}
|
||||
|
||||
pub fn args<T>(mut self, args: T) -> Self
|
||||
@@ -64,7 +72,7 @@ impl CommandBuilder {
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<Command> {
|
||||
debug_eprintln!("-----\n{self}\n-----");
|
||||
debug_eprintln!("running `{self}`");
|
||||
|
||||
let (first, rest) = self.args.split_first().context("empty args")?;
|
||||
let mut command = Command::new(first);
|
||||
|
||||
Reference in New Issue
Block a user