class Squarectl::Executor

Overview

The single point where child processes are spawned.

Everything squarectl does eventually funnels through here, which is what makes the rest of the code testable: specs inject an Executor whose output is an IO::Memory to capture commands instead of running them. Three modes: #run_command (spawn and wait for success), #exec_command (replace the current process — never returns) and #capture_output (collect stdout).

:nodoc:

Defined in:

squarectl/executor.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(output : IO::FileDescriptor | IO::Memory = STDOUT, error : IO::FileDescriptor | IO::Memory = STDERR) #

[View source]

Instance Method Detail

def capture_output(cmd : String, args : Array(String), env : Hash(String, String)) #

[View source]
def capture_output(cmd : String, args : Array(String)) #

Runs the command and returns its trimmed stdout, or nil if it failed or produced no output. Returning nil (rather than "") on empty output lets callers distinguish "nothing found" from a real value (see the container-id lookups in Commands::Swarm/Commands::Kubectl).


[View source]
def exec_command(cmd : String, args : Array(String), env : Hash(String, String)) : NoReturn #

Replaces the current process with the command; used for interactive commands (e.g. compose up, exec) so signals and the TTY pass through.


[View source]
def exec_command(cmd : String, args : Array(String)) #

[View source]
def run_command(cmd : String, args : Array(String), env : Hash(String, String), input : File) #

Variant that streams a file to the command's stdin (used to pipe config and secret contents into docker config/secret create).


[View source]
def run_command(cmd : String, args : Array(String), env : Hash(String, String)) #

Spawns the command, waits for it, and raises CommandError if it exits non-zero so the failure is not silently swallowed.


[View source]
def run_command(cmd : String, args : Array(String)) #

[View source]