pub struct ExecResult {
pub code: i64,
pub out: String,
pub err: String,
pub data: Option<Value>,
pub output: Option<OutputData>,
pub did_spill: bool,
pub original_code: Option<i64>,
}Expand description
The result of executing a command or pipeline.
Fields accessible via ${?.field}:
code— exit code (0 = success)ok— true if code == 0err— error message if failedout— raw stdout as stringdata— parsed JSON from stdout (if valid JSON)
Fields§
§code: i64Exit code. 0 means success.
out: StringRaw standard output as a string (canonical for pipes).
err: StringRaw standard error as a string.
data: Option<Value>Parsed JSON data from stdout, if stdout was valid JSON.
output: Option<OutputData>Structured output data for rendering.
did_spill: boolTrue if output was truncated and written to a spill file.
original_code: Option<i64>The command’s original exit code before spill logic overwrote it with 2 or 3.
Present only when did_spill is true and code was changed.
Implementations§
Source§impl ExecResult
impl ExecResult
Sourcepub fn success(out: impl Into<String>) -> ExecResult
pub fn success(out: impl Into<String>) -> ExecResult
Create a successful result with output.
Sourcepub fn with_output(output: OutputData) -> ExecResult
pub fn with_output(output: OutputData) -> ExecResult
Create a successful result with structured output data.
The OutputData is the source of truth. Text is materialized lazily
via text_out() when needed (pipes, redirects, command substitution).
For text-type output, JSON auto-detection still runs so that
echo '{"key":1}' populates data for command substitution.
Sourcepub fn success_data(data: Value) -> ExecResult
pub fn success_data(data: Value) -> ExecResult
Create a successful result with structured data.
Sourcepub fn success_with_data(out: impl Into<String>, data: Value) -> ExecResult
pub fn success_with_data(out: impl Into<String>, data: Value) -> ExecResult
Create a successful result with both text output and structured data.
Use this when a command should have:
- Text output for pipes and traditional shell usage
- Structured data for iteration and programmatic access
The data field takes precedence for command substitution in contexts
like for i in $(cmd) where the structured data can be iterated.
Sourcepub fn failure(code: i64, err: impl Into<String>) -> ExecResult
pub fn failure(code: i64, err: impl Into<String>) -> ExecResult
Create a failed result with an error message.
Sourcepub fn from_output(
code: i64,
stdout: impl Into<String>,
stderr: impl Into<String>,
) -> ExecResult
pub fn from_output( code: i64, stdout: impl Into<String>, stderr: impl Into<String>, ) -> ExecResult
Create a result from raw output streams.
JSON auto-detection: On success (code 0), stdout is checked for valid
JSON. If it parses, the result is stored in .data as structured data.
This enables for i in $(external-command) to iterate over JSON arrays
returned by MCP tools and external commands. This is intentional — external
tools communicate structured data via JSON stdout, and kaish makes it
available for iteration without requiring manual jq parsing.
Sourcepub fn with_output_and_text(
output: OutputData,
text: impl Into<String>,
) -> ExecResult
pub fn with_output_and_text( output: OutputData, text: impl Into<String>, ) -> ExecResult
Create a successful result with structured output and explicit pipe text.
Use this when a builtin needs custom text formatting that differs from
the canonical OutputData::to_canonical_string() representation.
Trait Implementations§
Source§impl Clone for ExecResult
impl Clone for ExecResult
Source§fn clone(&self) -> ExecResult
fn clone(&self) -> ExecResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more