Skip to main content

envelope_flat/
envelope_flat.rs

1//! Flat JSON envelope — the default layout.
2//!
3//! All fields (`ok`, `format`, content, `meta`) appear at the top level.
4//!
5//! Run with:
6//! ```sh
7//! cargo run --example envelope_flat
8//! ```
9
10use scriba::{
11    Format, Output,
12    Ui,
13    envelope::{EnvelopeConfig, EnvelopeLayout, EnvelopeMode, Meta},
14};
15
16fn main() -> scriba::Result<()> {
17    let output = Output::new()
18        .title("Deployment")
19        .data("environment", "production")
20        .data("version", "1.4.2")
21        .paragraph("All services healthy.");
22
23    let ui = Ui::new()
24        .with_format(Format::Json)
25        .with_envelope(
26            EnvelopeConfig::default()
27                .with_mode(EnvelopeMode::Json)
28                .with_layout(EnvelopeLayout::Flat),
29        );
30
31    println!("=== Flat envelope, no meta ===");
32    ui.print(&output)?;
33
34    println!("\n=== Flat envelope, with meta ===");
35    let meta = Meta::default()
36        .with_dry_run(false)
37        .with_command("deploy".into())
38        .with_duration_ms(312)
39        .with_timestamp("2026-04-13T15:00:00Z".into());
40    ui.print_with_meta(&output, Some(&meta), true)?;
41
42    println!("\n=== Flat envelope, ok: false (error case) ===");
43    let error_output = Output::new()
44        .title("Deployment")
45        .paragraph("Health check failed on eu-west-1.");
46    ui.print_with_meta(&error_output, None, false)?;
47
48    Ok(())
49}