Module: Rakit::Shell

Defined in:
lib/rakit/shell.rb,
lib/generated/shell_pb.rb

Defined Under Namespace

Modules: CommandService

Constant Summary collapse

CHECK =
"\e[32m✓\e[0m"
CROSS =
"\e[31m✗\e[0m"
Command =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.Command").msgclass
AcceptanceCriteria =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.AcceptanceCriteria").msgclass
TestResult =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.TestResult").msgclass
FormatRequest =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.FormatRequest").msgclass
FormatResponse =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.FormatResponse").msgclass
CommandFormat =
::Google::Protobuf::DescriptorPool.generated_pool.lookup("rakit.shell.CommandFormat").enummodule

Class Method Summary collapse

Class Method Details

.run(cmd) ⇒ Object

Run a shell command string (like sh). Builds a Command (sh -c “cmd”) and executes it. Prints ✓ (green) + cmd on success, or ✗ (red) + cmd then stdout/stderr on failure. Returns the Command with result fields set.



191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/rakit/shell.rb', line 191

def self.run(cmd)
  command = Command.new(name: "sh", args: ["-c", cmd.to_s], working_directory: "")
  result = CommandService.execute(command)
  if result.exit_status == 0
    puts "#{CHECK} #{cmd}"
  else
    puts "#{CROSS} #{cmd}"
    puts "stdout:\n#{result.stdout}" if result.stdout && !result.stdout.empty?
    puts "stderr:\n#{result.stderr}" if result.stderr && !result.stderr.empty?
  end
  result
end