JustBash.Result (JustBash v0.4.0)
View SourceRepresents the result of executing a command or script.
Contains stdout, stderr, exit code, and optional control flow signals.
Control Flow Signals
Shell control flow (break, continue, return) is handled through the signal field:
nil- No signal, normal execution{:break, n}- Break from n loop levels{:continue, n}- Continue at n loop levels{:return, code}- Return from function with exit code
Summary
Functions
Creates a result with a break signal.
Checks if the result has a break signal.
Creates a result with a continue signal.
Checks if the result has a continue signal.
Decrements the signal level by 1. Returns nil if level reaches 0. Only applicable to break and continue signals.
Creates an error result with the given stderr and exit code.
Converts from a plain map (for backward compatibility during migration).
Checks if the result has any control flow signal.
Merges output from one result into another, preserving the signal from source if present.
Creates a new result with the given attributes.
Creates a successful result with the given stdout.
Creates a result with a return signal.
Checks if the result has a return signal.
Converts to a plain map (for backward compatibility during migration).
Types
@type signal() :: {:break, pos_integer()} | {:continue, pos_integer()} | {:return, non_neg_integer()} | nil
@type t() :: %JustBash.Result{ exit_code: non_neg_integer(), signal: signal(), stderr: String.t(), stdout: String.t() }
Functions
@spec break(pos_integer()) :: t()
Creates a result with a break signal.
Checks if the result has a break signal.
@spec continue(pos_integer()) :: t()
Creates a result with a continue signal.
Checks if the result has a continue signal.
Decrements the signal level by 1. Returns nil if level reaches 0. Only applicable to break and continue signals.
@spec error(String.t(), non_neg_integer()) :: t()
Creates an error result with the given stderr and exit code.
Converts from a plain map (for backward compatibility during migration).
Checks if the result has any control flow signal.
Merges output from one result into another, preserving the signal from source if present.
Creates a new result with the given attributes.
Examples
iex> JustBash.Result.new()
%JustBash.Result{stdout: "", stderr: "", exit_code: 0, signal: nil}
iex> JustBash.Result.new(stdout: "hello\n", exit_code: 0)
%JustBash.Result{stdout: "hello\n", stderr: "", exit_code: 0, signal: nil}
Creates a successful result with the given stdout.
@spec return(non_neg_integer()) :: t()
Creates a result with a return signal.
Checks if the result has a return signal.
Converts to a plain map (for backward compatibility during migration).