slave 0.4.0

Laravel-inspired CLI for Rust MCP servers: scaffold apps whose business operations are MCP tools over Streamable HTTP, with built-in auth, users, roles and Turso migrations
//! `slave migrate`, `migrate:status` and `migrate:rollback`.
//!
//! Migrations are Rust code compiled into the application, so these commands
//! build and run the application's `migrate` binary (`src/bin/migrate.rs`),
//! which drives the migration engine in `slave-framework`.

use anyhow::{Result, bail};

use crate::{cargo, project};

#[derive(Debug, Clone, Copy)]
pub enum Action {
    Run,
    Status,
    Rollback,
}

impl Action {
    fn arg(self) -> &'static str {
        match self {
            Self::Run => "run",
            Self::Status => "status",
            Self::Rollback => "rollback",
        }
    }
}

pub fn run(action: Action) -> Result<()> {
    let root = project::find_root()?;
    if !root.join("src/bin/migrate.rs").is_file() {
        bail!(
            "src/bin/migrate.rs not found; this application was created without migration support"
        );
    }

    let status = cargo::run(
        &root,
        &["run", "--quiet", "--bin", "migrate", "--", action.arg()],
        &[],
    )?;
    if !status.success() {
        bail!("`{}` did not complete successfully", command_name(action));
    }
    Ok(())
}

fn command_name(action: Action) -> &'static str {
    match action {
        Action::Run => "slave migrate",
        Action::Status => "slave migrate:status",
        Action::Rollback => "slave migrate:rollback",
    }
}