//! CLI Tools Module
//!
//! Command-line interface utilities for development workflows.

use std::process::{Command, Output};

use anyhow::Result;

/// Run a shell command and return the output
pub fn run_command(cmd: &str, args: &[&str]) -> Result<Output> {
    let output = Command::new(cmd).args(args).output()?;

    Ok(output)
}

/// Execute a development workflow command
pub fn execute_dev_workflow(workflow: &str) -> Result<()> {
    match workflow {
        "build" => {
            let output = run_command("cargo", &["leptos", "build"])?;
            if !output.status.success() {
                return Err(anyhow::anyhow!("Build failed"));
            }
        }
        "dev" => {
            let output = run_command("cargo", &["leptos", "watch"])?;
            if !output.status.success() {
                return Err(anyhow::anyhow!("Dev server failed to start"));
            }
        }
        _ => return Err(anyhow::anyhow!("Unknown workflow: {}", workflow)),
    }

    Ok(())
}
