flowcode-core 0.4.3-alpha

Core execution engine for FlowCode data scripting language
Documentation
//! Stand-alone helper to regenerate `docs/verbs.md` from `spec::SPECS`.
//! Requires `--features json` so we can call `get_specs_json()`.
//!
//! Typical usage (CI):
//!
//!     FCSPECS=1 cargo run -p flowcode-core --bin schema2md --features json > docs/verbs.md
//!
//! If the environment variable `FCSPECS` is **not** set, this binary exits
//! quickly so normal builds/tests remain fast.

use std::{env};
// use std::fs::File;
// use std::io::Read;

#[cfg(feature = "json")]
use std::io::Write;

#[cfg(feature = "json")]
use serde_json::Value;

fn main() {
    // Only run when explicitly requested.
    if env::var("FCSPECS").is_err() {
        eprintln!("schema2md: FCSPECS not set – nothing to do");
        return;
    }

    #[cfg(feature = "json")]
    {
        // Pull JSON from core helper.
        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);
            }
        };

        // Render the Markdown table.
        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");

        // Print to stdout (caller can redirect).
        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);
    }
}