openlatch-provider 0.2.1

Self-service onboarding CLI + runtime daemon for OpenLatch Editors and Providers
//! Output-mode dispatch helpers. T0 exposes a single helper that picks the
//! right serializer for a given `OutputFormat`; the rest of the rendering
//! surface lands in P1.T2.5.

use crate::cli::OutputFormat;
use crate::error::{OlError, OL_4270_CONFIG_UNREADABLE};
use serde::Serialize;

/// Serialize `value` to the wire format implied by `format` and write it to
/// stdout. `Sarif` is intentionally TBD — `bindings probe` (P1.T5) and
/// `doctor` (P2.T7) plug into a richer SARIF helper there.
pub fn render<T: Serialize>(format: OutputFormat, value: &T) -> Result<(), OlError> {
    match format {
        OutputFormat::Json => {
            let s = serde_json::to_string_pretty(value)
                .map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("json: {e}")))?;
            println!("{s}");
            Ok(())
        }
        OutputFormat::Yaml => {
            let s = serde_yaml::to_string(value)
                .map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("yaml: {e}")))?;
            print!("{s}");
            Ok(())
        }
        OutputFormat::Table | OutputFormat::Sarif => {
            // Table renderers are command-specific (`tabled` derive structs in
            // src/ui/tables.rs); SARIF is wired in P1.T5. Falling back to JSON
            // keeps the CLI output sane until the rich renderers land.
            let s = serde_json::to_string_pretty(value)
                .map_err(|e| OlError::new(OL_4270_CONFIG_UNREADABLE, format!("json: {e}")))?;
            println!("{s}");
            Ok(())
        }
    }
}