class BlueShell::Runner
Public Class Methods
new(*args) { |self| ... }
click to toggle source
# File lib/blue-shell/runner.rb, line 10 def initialize(*args) @stdout, slave = PTY.open system('stty raw', :in => slave) read, @stdin = IO.pipe @pid = spawn(*(args.push(:in => read, :out => slave, :err => slave))) @expector = BufferedReaderExpector.new(@stdout, ENV['DEBUG_BACON']) if block_given? yield self else wait_for_exit end end
Public Instance Methods
debug()
click to toggle source
# File lib/blue-shell/runner.rb, line 94 def debug @expector.debug end
debug=(x)
click to toggle source
# File lib/blue-shell/runner.rb, line 98 def debug=(x) @expector.debug = x end
exit_code()
click to toggle source
# File lib/blue-shell/runner.rb, line 59 def exit_code return @code if @code code = nil begin Timeout.timeout(BlueShell.timeout) do _, code = Process.waitpid2(@pid) end rescue Timeout::Error raise ::Timeout::Error.new("execution expired, output was:\n#{@expector.read_to_end}") end @code = numeric_exit_code(code) end
Also aliased as: wait_for_exit
exited?()
click to toggle source
# File lib/blue-shell/runner.rb, line 76 def exited? !running? end
expect(matcher)
click to toggle source
# File lib/blue-shell/runner.rb, line 30 def expect(matcher) case matcher when Hash expect_branches(matcher) else @expector.expect(matcher) end end
output()
click to toggle source
# File lib/blue-shell/runner.rb, line 90 def output @expector.output end
running?()
click to toggle source
# File lib/blue-shell/runner.rb, line 86 def running? !!Process.getpgid(@pid) end
send_backspace()
click to toggle source
# File lib/blue-shell/runner.rb, line 47 def send_backspace @stdin.print("\b \b") end
send_keys(text_to_send)
click to toggle source
# File lib/blue-shell/runner.rb, line 51 def send_keys(text_to_send) @stdin.puts(text_to_send) end
send_return()
click to toggle source
# File lib/blue-shell/runner.rb, line 55 def send_return @stdin.puts end
send_right_arrow()
click to toggle source
# File lib/blue-shell/runner.rb, line 43 def send_right_arrow @stdin.print("\e[C") end
send_up_arrow()
click to toggle source
# File lib/blue-shell/runner.rb, line 39 def send_up_arrow @stdin.print("\e[A") end
success?()
click to toggle source
# File lib/blue-shell/runner.rb, line 80 def success? @code.zero? end
Also aliased as: successful?
with_timeout(timeout, &block)
click to toggle source
# File lib/blue-shell/runner.rb, line 26 def with_timeout(timeout, &block) BlueShell.with_timeout(timeout, &block) end
Private Instance Methods
expect_branches(branches)
click to toggle source
# File lib/blue-shell/runner.rb, line 104 def expect_branches(branches) branch_names = /#{branches.keys.collect { |k| Regexp.quote(k) }.join('|')}/ expected = @expector.expect(branch_names) return unless expected data = expected.first.match(/(#{branch_names})$/) matched = data[1] branches[matched].call matched end
numeric_exit_code(status)
click to toggle source
# File lib/blue-shell/runner.rb, line 115 def numeric_exit_code(status) status.exitstatus rescue NoMethodError status end