cargo-governor 2.0.3

Machine-First, LLM-Ready, CI/CD-Native release automation tool for Rust crates
Documentation
//! CLI presenters for machine-readable output.

use serde::Serialize;

use crate::error::Result;

#[derive(Debug, Serialize)]
pub struct Metrics {
    execution_time_ms: u128,
}

#[derive(Debug, Serialize)]
pub struct Envelope<T> {
    schema_version: u32,
    success: bool,
    command: String,
    workspace: Option<String>,
    data: T,
    errors: Vec<String>,
    metrics: Metrics,
}

pub fn print_json<T: Serialize>(
    command: &str,
    workspace: Option<String>,
    success: bool,
    data: T,
    started_at: std::time::Instant,
    errors: Vec<String>,
) -> Result<()> {
    let envelope = Envelope {
        schema_version: 2,
        success,
        command: command.to_string(),
        workspace,
        data,
        errors,
        metrics: Metrics {
            execution_time_ms: started_at.elapsed().as_millis(),
        },
    };
    println!(
        "{}",
        serde_json::to_string_pretty(&envelope)
            .map_err(|error| crate::error::Error::Serialization(error.to_string()))?
    );
    Ok(())
}