testcontainers-build 0.1.0

Build Testcontainers images from folders, remote contexts, and pluggable Git providers
Documentation
use crate::{Error, Result};
use std::path::Path;
use tokio::process::Command;

pub(crate) async fn run(
    program: &str,
    args: &[std::ffi::OsString],
    directory: Option<&Path>,
) -> Result<String> {
    let mut cmd = Command::new(program);
    cmd.args(args)
        .kill_on_drop(true)
        .env("GIT_TERMINAL_PROMPT", "0");
    if let Some(directory) = directory {
        cmd.current_dir(directory);
    }
    #[cfg(windows)]
    cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
    let result = cmd.output().await?;
    if !result.status.success() {
        return Err(Error::Command {
            program: Path::new(program)
                .file_name()
                .unwrap_or_default()
                .to_string_lossy()
                .into(),
            code: result.status.code(),
            output: format!(
                "{}\n{}",
                String::from_utf8_lossy(&result.stderr),
                String::from_utf8_lossy(&result.stdout)
            ),
        });
    }
    Ok(String::from_utf8_lossy(&result.stdout).into())
}