quillmark-cli 0.127.0

Command-line interface for Quillmark, a schema-driven document engine
mod commands;
mod errors;
mod output;

use clap::{Parser, Subcommand};
use std::process;
use std::sync::LazyLock;

static VERSION: LazyLock<String> = LazyLock::new(|| {
    format!(
        "{} (Typst {})",
        env!("CARGO_PKG_VERSION"),
        quillmark::typst_version()
    )
});

#[derive(Parser)]
#[command(name = "quillmark")]
#[command(about = "Command-line interface for Quillmark: a schema-driven document engine", long_about = None)]
#[command(version = VERSION.as_str())]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// Render markdown file to output format
    Render(commands::render::RenderArgs),

    /// Check markdown files against a quill's schema, printing every diagnostic
    Check(commands::check::CheckArgs),

    /// Output the YAML schema for a quill
    Schema(commands::schema::SchemaArgs),

    /// Output the annotated Markdown blueprint for a quill
    Blueprint(commands::blueprint::BlueprintArgs),

    /// Validate a quill's configuration and compile its plate
    Validate(commands::validate::ValidateArgs),

    /// Display a quill's identity and schema counts
    Info(commands::info::InfoArgs),

    /// Write the files Typst's own tooling needs to compile a quill's plate
    Workspace(commands::workspace::WorkspaceArgs),
}

fn main() {
    let cli = Cli::parse();

    let result = match cli.command {
        Commands::Render(args) => commands::render::execute(args),
        Commands::Check(args) => commands::check::execute(args),
        Commands::Schema(args) => commands::schema::execute(args),
        Commands::Blueprint(args) => commands::blueprint::execute(args),
        Commands::Validate(args) => commands::validate::execute(args),
        Commands::Info(args) => commands::info::execute(args),
        Commands::Workspace(args) => commands::workspace::execute(args),
    };

    if let Err(e) = result {
        errors::print_cli_error(&e);
        process::exit(1);
    }
}