class TestLauncher::Shell::Runner

Constants

CommandFailureError

Attributes

log_path[RW]
queue[RW]

Public Class Methods

new(log_path: "/dev/null") click to toggle source
# File lib/test_launcher/shell/runner.rb, line 14
def initialize(log_path: "/dev/null")
  @log_path = log_path
  %x{echo "" > #{log_path}}
end

Public Instance Methods

confirm?(question) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 47
def confirm?(question)
  warn "#{question} [Yn]"
  STDIN.gets.strip.downcase != 'n'
end
exec(cmd) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 26
def exec(cmd)
  notify cmd
  $stdout.flush
  Kernel.exec cmd
end
notify(msg) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 37
def notify(msg)
  log msg
  print "#{yellow(msg)}\n"
end
puts(msg) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 42
def puts(msg)
  log msg
  print "#{msg}\n"
end
run(cmd, dir: ".") click to toggle source
# File lib/test_launcher/shell/runner.rb, line 19
def run(cmd, dir: ".")
  command = "cd #{dir} && #{cmd}"
  log(command)

  shell_out(command).split("\n")
end
warn(msg) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 32
def warn(msg)
  log msg
  print "#{red(msg)}\n"
end

Private Instance Methods

log(msg) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 54
def log(msg)
  %x{echo #{Shellwords.escape(msg)} >> #{log_path}}
end
shell_out(command) click to toggle source
# File lib/test_launcher/shell/runner.rb, line 58
def shell_out(command)
  logged_cmd = "set -o pipefail && #{command} 2>> #{log_path} | tee -a #{log_path}"
  %x{bash -c #{Shellwords.escape(logged_cmd)}}.chomp
end