Skip to main content

emit

Function emit 

Source
pub fn emit<T: Serialize>(
    data: &T,
    format: OutputFormat,
    exit_code: ExitCode,
) -> Result<ExitCode>
Expand description

Formats data per format, prints it to stdout, and returns exit_code.

Collapses the format/print/return-exit-code sequence repeated across every CLI command handler’s branches into a single call site, so each branch only has to state which exit code it wants.

§Errors

Returns an error if formatting data fails (see format_output).

§Examples

use mcp_execution_cli::formatters::emit;
use mcp_execution_core::cli::{ExitCode, OutputFormat};
use serde::Serialize;

#[derive(Serialize)]
struct Data {
    value: i32,
}

let code = emit(&Data { value: 42 }, OutputFormat::Json, ExitCode::SUCCESS)?;
assert_eq!(code, ExitCode::SUCCESS);