matcha-cli 26.11.0-rc.1

The green-tea CLI: scaffold a project, generate controllers, steps and providers already wired into their module, and run with your runtime detected. One native binary, no JS runtime needed to install it.
mod ask;
mod check;
mod cli;
mod cmd_add;
mod cmd_agents;
mod cmd_create;
mod cmd_doctor;
mod cmd_graph;
mod cmd_new;
mod cmd_plugin;
mod cmd_run;
mod entry;
mod introspect;
mod naming;
mod plugin_files;
mod runtime;
mod template;
mod wire;

use clap::Parser;
use cli::{Cli, Command};

fn main() {
    let cli = Cli::parse();
    match cli.command {
        Command::New {
            name,
            template_url,
            runtime,
        } => {
            if let Err(e) = cmd_new::run(&name, template_url.as_deref(), &runtime) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Run => {
            if let Err(e) = cmd_run::run(std::path::Path::new(".")) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Create {
            kind,
            name,
            check,
            package,
            folder,
            scope,
            registry,
            npm_name,
        } => {
            let stray: Vec<&str> = [
                ("--package", package.is_some()),
                ("--folder", folder.is_some()),
                ("--scope", scope.is_some()),
                ("--registry", registry.is_some()),
                ("--npm-name", npm_name.is_some()),
            ]
            .into_iter()
            .filter(|(_, on)| *on)
            .map(|(flag, _)| flag)
            .collect();
            let result = if kind != "plugin" && !stray.is_empty() {
                Err(std::io::Error::new(
                    std::io::ErrorKind::InvalidInput,
                    format!("{} only apply to create plugin", stray.join(", ")),
                ))
            } else if kind == "plugin" {
                cmd_plugin::run(cmd_plugin::Opts {
                    name,
                    package,
                    folder,
                    scope,
                    registry,
                    npm_name,
                    check,
                })
            } else {
                match name {
                    Some(name) => cmd_create::run(&kind, &name, check),
                    None => Err(std::io::Error::new(
                        std::io::ErrorKind::InvalidInput,
                        format!("create {kind} needs a name"),
                    )),
                }
            };
            if let Err(e) = result {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Agents { force } => {
            if let Err(e) = cmd_agents::run(std::path::Path::new("."), force) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Doctor => {
            if let Err(e) = cmd_doctor::run(std::path::Path::new(".")) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Graph { format, entry, out } => {
            if let Err(e) = cmd_graph::graph(
                std::path::Path::new("."),
                &format,
                entry.as_deref(),
                out.as_deref(),
            ) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Openapi {
            title,
            api_version,
            entry,
            out,
        } => {
            if let Err(e) = cmd_graph::openapi(
                std::path::Path::new("."),
                title.as_deref(),
                api_version.as_deref(),
                entry.as_deref(),
                out.as_deref(),
            ) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Explain {
            route,
            entry,
            out,
            json,
        } => {
            if let Err(e) = cmd_graph::explain(
                std::path::Path::new("."),
                &route,
                entry.as_deref(),
                out.as_deref(),
                render(json),
            ) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Routes { entry, out, json } => {
            if let Err(e) = cmd_graph::routes(
                std::path::Path::new("."),
                entry.as_deref(),
                out.as_deref(),
                render(json),
            ) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Tokens { entry, out, json } => {
            if let Err(e) = cmd_graph::tokens(
                std::path::Path::new("."),
                entry.as_deref(),
                out.as_deref(),
                render(json),
            ) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
        Command::Add {
            capability,
            controller,
        } => {
            if let Err(e) = cmd_add::run(&capability, controller.as_deref()) {
                eprintln!("error: {e}");
                std::process::exit(1);
            }
        }
    }
}

fn render(json: bool) -> cmd_graph::Render {
    if json {
        cmd_graph::Render::Json
    } else {
        cmd_graph::Render::Text
    }
}