slave 0.9.1

CLI for slave, a Laravel-inspired Rust framework for MCP-first apps: scaffold an MCP backend with auth, roles and Toasty models and migrations, add server-rendered web apps, and route them by domain or path
//! Running Cargo inside a slave application.

use std::ffi::OsString;
use std::io::ErrorKind;
use std::path::Path;
use std::process::{Command, ExitStatus};

use anyhow::{Context, Result, bail};

/// A `cargo` command, honoring the `CARGO` variable set by Cargo itself.
pub fn command() -> Command {
    Command::new(std::env::var_os("CARGO").unwrap_or_else(|| OsString::from("cargo")))
}

/// Runs `cargo <args>` in `root` with extra environment variables, inheriting stdio.
pub fn run(root: &Path, args: &[&str], envs: &[(&str, &str)]) -> Result<ExitStatus> {
    let mut command = command();
    command.args(args).current_dir(root);
    for (key, value) in envs {
        command.env(key, value);
    }

    match command.status() {
        Ok(status) => Ok(status),
        Err(err) if err.kind() == ErrorKind::NotFound => {
            bail!("`cargo` was not found on your PATH; install Rust from https://rustup.rs")
        }
        Err(err) => {
            Err(err).with_context(|| format!("failed to launch `cargo {}`", args.join(" ")))
        }
    }
}