use std::{env};
#[cfg(feature = "json")]
use std::io::Write;
#[cfg(feature = "json")]
use serde_json::Value;
fn main() {
if env::var("FCSPECS").is_err() {
eprintln!("schema2md: FCSPECS not set – nothing to do");
return;
}
#[cfg(feature = "json")]
{
let json = match flowcode_core::spec::get_specs_json() {
Ok(j) => j,
Err(e) => {
eprintln!("schema2md: unable to create JSON from SPECS: {e}");
std::process::exit(1);
}
};
let specs: Vec<Value> = match serde_json::from_str(&json) {
Ok(v) => v,
Err(e) => {
eprintln!("schema2md: invalid JSON from get_specs_json: {e}");
std::process::exit(1);
}
};
let mut md = String::from("# FlowCode Verbs\n\n| Name | Behaviour | Syntax |\n|------|-----------|--------|\n");
for spec in specs {
md.push_str(&format!(
"| `{}` | {} | `{}` |\n",
spec["name"].as_str().unwrap(),
spec["description"].as_str().unwrap(),
spec["syntax"].as_str().unwrap(),
));
}
md.push_str("\n*Auto-generated; do not edit manually.*\n");
let mut stdout = std::io::stdout();
stdout.write_all(md.as_bytes()).expect("write stdout");
}
#[cfg(not(feature = "json"))]
{
eprintln!("schema2md: compiled without 'json' feature");
std::process::exit(1);
}
}