CI / installer (macos-14) (pull_request) Successful in 4s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Successful in 30s
CI / starter (deno) (pull_request) Successful in 32s
CI / starter (edge) (pull_request) Successful in 36s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Successful in 14s
CI / starter (node) (pull_request) Successful in 32s
Agents that inspect a green-tea app should read its graph instead of guessing it. - Add `matcha routes`: every route with its transport and chain. - Add `matcha tokens`: every token, who provides it and who needs it, handlers included. - explain, routes and tokens take --json. It prints one JSON document on stdout; a refused query prints a structured error on stderr and exits 1. All introspection now goes through src/introspect.rs. Each Query variant runs one script that prints a single JSON envelope, and the CLI renders the data as text unless --json is given. Text output is unchanged. A future `matcha mcp` serves the same queries as tools without a second implementation, which is why the formatting moved from the generated script into Rust. Adds serde_json (dtolnay, 1.0.154). Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
183 lines
5.0 KiB
Rust
183 lines
5.0 KiB
Rust
mod ask;
|
|
mod check;
|
|
mod cli;
|
|
mod cmd_add;
|
|
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::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
|
|
}
|
|
}
|