Skip to main content

envelope_nested/
envelope_nested.rs

1//! Nested JSON envelope layout.
2//!
3//! `ok`, `format`, and all user metadata are merged under the `meta` key.
4//! The content payload sits alongside at the top level.
5//!
6//! Output shape:
7//! ```json
8//! {
9//!   "meta": { "ok": true, "format": "json", "dry_run": true, "timestamp": "..." },
10//!   "content": { ... }
11//! }
12//! ```
13//!
14//! Run with:
15//! ```sh
16//! cargo run --example envelope_nested
17//! ```
18
19use scriba::{
20    Format, Output,
21    Ui,
22    envelope::{EnvelopeConfig, EnvelopeLayout, EnvelopeMode, Meta},
23};
24
25fn main() -> scriba::Result<()> {
26    let output = Output::new()
27        .title("Pipeline")
28        .data("stage", "build")
29        .data("commit", "a3f9c12")
30        .paragraph("Build succeeded in 42s.");
31
32    let ui = Ui::new()
33        .with_format(Format::Json)
34        .with_envelope(
35            EnvelopeConfig::default()
36                .with_mode(EnvelopeMode::Json)
37                .with_layout(EnvelopeLayout::Nested),
38        );
39
40    println!("=== Nested envelope, no meta ===");
41    ui.print(&output)?;
42
43    println!("\n=== Nested envelope, with meta merged in ===");
44    let meta = Meta::default()
45        .with_dry_run(true)
46        .with_command("ci run".into())
47        .with_timestamp("2026-04-13T09:30:00Z".into())
48        .with_scope("ci".into())
49        .with_version("0.3.0".into());
50    ui.print_with_meta(&output, Some(&meta), true)?;
51
52    Ok(())
53}