Class: Rooibos::Command::System
- Inherits:
-
Object
- Object
- Rooibos::Command::System
- Includes:
- Custom
- Defined in:
- lib/rooibos/command.rb
Overview
Runs a shell command and routes its output back as messages.
Apps run external tools: linters, compilers, scripts, system utilities. The runtime dispatches the command in a thread, so the UI stays responsive. Batch mode (default) waits for completion; streaming mode shows output live. Orphaned child processes linger and waste resources, so cancellation sends SIGTERM for graceful shutdown, then SIGKILL to prevent orphans.
Use it to run builds, lint files, execute scripts, or invoke any CLI tool.
Prefer the Command.system factory method for convenience.
Batch Mode (default)
A single message arrives when the command finishes: Message::System::Batch with stdout, stderr, status.
Streaming Mode
Message::System::Stream messages arrive incrementally:
stream: :stdout-
for each stdout chunk
stream: :stderr-
for each stderr chunk
stream: :complete-
when the command finishes
stream: :error-
if the command cannot start
Example
# Using the factory method (recommended)
Command.system("ls -la", :got_files)
Command.system("tail -f log.txt", :log, stream: true)
# Using the class directly
System.new(command: "ls -la", envelope: :got_files, stream: false)
Instance Method Summary collapse
-
#call(out, token) ⇒ Object
Executes the shell command and sends results via outlet.
-
#stream? ⇒ Boolean
Returns true if streaming mode is enabled.
Methods included from Custom
#deconstruct_keys, #rooibos_cancellation_grace_period, #rooibos_command?
Instance Method Details
#call(out, token) ⇒ Object
Executes the shell command and sends results via outlet.
In batch mode, sends a single message with all output. In streaming mode, sends incremental messages as output arrives. Respects cancellation token by sending SIGTERM (then SIGKILL) to child.
306 307 308 309 310 311 312 313 314 |
# File 'lib/rooibos/command.rb', line 306 def call(out, token) require "open3" if stream? stream_execution(out, token) else batch_execution(out) end end |
#stream? ⇒ Boolean
Returns true if streaming mode is enabled.
297 298 299 |
# File 'lib/rooibos/command.rb', line 297 def stream? stream end |