Skip to main content

ferro_cli/commands/
json_ui_schema.rs

1use console::style;
2use std::path::Path;
3use std::process::Command;
4
5/// Invoke the unified `ferro` binary's `json-ui:schema` subcommand from the
6/// workspace root via `cargo run --quiet`.
7///
8/// Mirrors the `db_status.rs` shell-out pattern. Requires a `Cargo.toml` in
9/// the current directory to confirm the caller is inside a Ferro project.
10pub fn run(output: Option<String>, pretty: bool, component: Option<String>) {
11    if !Path::new("Cargo.toml").exists() {
12        eprintln!(
13            "{} This command must be run from a Ferro project root (no Cargo.toml found)",
14            style("Error:").red().bold()
15        );
16        std::process::exit(1);
17    }
18
19    let mut args: Vec<String> = vec![
20        "run".into(),
21        "--quiet".into(),
22        "--".into(),
23        "json-ui:schema".into(),
24    ];
25    if let Some(o) = output.as_deref() {
26        args.push("--output".into());
27        args.push(o.to_string());
28    }
29    if pretty {
30        args.push("--pretty".into());
31    }
32    if let Some(c) = component.as_deref() {
33        args.push("--component".into());
34        args.push(c.to_string());
35    }
36
37    let status = Command::new("cargo")
38        .args(&args)
39        .status()
40        .expect("Failed to execute cargo command");
41
42    if !status.success() {
43        eprintln!("{} Schema export failed", style("Error:").red().bold());
44        std::process::exit(1);
45    }
46}