pub struct Output { /* private fields */ }Expand description
Result type that handles output formatting and exit codes.
Builds and emits Agent-First Data protocol events through agent_first_data::CliEmitter.
Implementations§
Source§impl Output
impl Output
pub fn new(format: OutputFormat) -> Self
Sourcepub fn ok<T: Serialize>(&self, result: T) -> ExitCode
pub fn ok<T: Serialize>(&self, result: T) -> ExitCode
{kind: "result", result: ..., trace: {}} → stdout.
Sourcepub fn ok_trace<T: Serialize>(
&self,
result: T,
trace: impl Serialize,
) -> ExitCode
pub fn ok_trace<T: Serialize>( &self, result: T, trace: impl Serialize, ) -> ExitCode
{kind: "result", result: ..., trace: ...} → stdout.
Sourcepub fn ok_with_code<T: Serialize>(&self, result: T, code: u8) -> ExitCode
pub fn ok_with_code<T: Serialize>(&self, result: T, code: u8) -> ExitCode
{kind: "result", result: ...} → stdout, with a caller-chosen exit code.
For machine-checkable “is there drift” style results (e.g. hatch bond sync --check) where the outcome is a normal, well-formed result (not an
error) but CI still needs a distinct non-zero exit to gate on.
Sourcepub fn error(&self, error_code: &str, message: &str) -> ExitCode
pub fn error(&self, error_code: &str, message: &str) -> ExitCode
{kind: "error", error: {code, message, hint, retryable}, trace} → stdout.
Sourcepub fn error_hint(
&self,
error_code: &str,
message: &str,
hint: Option<&str>,
) -> ExitCode
pub fn error_hint( &self, error_code: &str, message: &str, hint: Option<&str>, ) -> ExitCode
Like [error] but with an actionable hint for remediation.
Sourcepub fn error_from(&self, error_code: &str, err: &Error) -> ExitCode
pub fn error_from(&self, error_code: &str, err: &Error) -> ExitCode
Output error from anyhow::Error
Sourcepub fn error_hypha(&self, err: &HyphaError) -> ExitCode
pub fn error_hypha(&self, err: &HyphaError) -> ExitCode
Output error from crate::HyphaError (includes hint when present).
Sourcepub fn progress(&self, step: u32, total: u32, message: &str, data: Value)
pub fn progress(&self, step: u32, total: u32, message: &str, data: Value)
Agent-First Data progress step → stdout
{kind: "progress", progress: {current, total, message, ...}, trace}.
Sourcepub fn download_progress(&self, downloaded_bytes: u64, total_bytes: Option<u64>)
pub fn download_progress(&self, downloaded_bytes: u64, total_bytes: Option<u64>)
Byte-level protocol-v1 download progress → stdout.
{kind: "progress", progress: {event, downloaded_bytes, total_bytes}}.