Skip to main content

agent_first_http/cli/
output.rs

1//! Output glue. The single seam through which CLI subcommands write their
2//! one line of JSON to stdout.
3
4use serde::Serialize;
5use std::io::Write;
6
7use crate::shared::error::Error;
8
9/// Emit a payload to stdout as one line of JSON. Wraps
10/// `shared::envelope::emit` and is the single seam through which CLI
11/// subcommands produce output.
12pub fn emit<T: Serialize>(code: &str, payload: &T) -> Result<(), Error> {
13    let stdout = std::io::stdout();
14    let mut handle = stdout.lock();
15    crate::shared::envelope::emit(&mut handle, code, payload)?;
16    handle.flush().ok();
17    Ok(())
18}