module Aruba::Api::Commands
def all_commands
-
(Array)
-
def all_commands aruba.command_monitor.registered_commands end
def all_output
-
(String)
-
def all_output aruba.command_monitor.all_output end
def all_stderr
-
(String)
-
def all_stderr aruba.command_monitor.all_stderr end
def all_stdout
-
(String)
-
def all_stdout aruba.command_monitor.all_stdout end
def close_input
def close_input last_command_started.close_io(:stdin) end
def find_command(commandline)
-
commandline
(String, Command
) --
def find_command(commandline) aruba.command_monitor.find(commandline) end
def last_command_started
def last_command_started aruba.command_monitor.last_command_started end
def last_command_stopped
def last_command_stopped aruba.command_monitor.last_command_stopped end
def pipe_in_file(file_name)
-
file_name
(String
) --
def pipe_in_file(file_name) file_name = expand_path(file_name) File.open(file_name, "r").each_line do |line| last_command_started.write(line) end end
def prepare_command(cmd, opts)
def prepare_command(cmd, opts) exit_timeout = opts[:exit_timeout] || aruba.config.exit_timeout io_wait_timeout = opts[:io_wait_timeout] || aruba.config.io_wait_timeout stop_signal = opts[:stop_signal] || aruba.config.stop_signal startup_wait_time = opts[:startup_wait_time] || aruba.config.startup_wait_time @commands ||= [] @commands << cmd environment = aruba.environment working_directory = expand_path(".") event_bus = aruba.event_bus cmd = Aruba.platform.detect_ruby(cmd) mode = aruba.config.command_launcher main_class = aruba.config.main_class Command.new( cmd, mode: mode, exit_timeout: exit_timeout, io_wait_timeout: io_wait_timeout, working_directory: working_directory, environment: environment.to_hash, main_class: main_class, stop_signal: stop_signal, startup_wait_time: startup_wait_time, event_bus: event_bus ) end
def run_command(cmd, opts = {})
- Yield: -
Options Hash:
(**opts)
-
stop_signal
(String
) -- -
startup_wait_time
(Numeric
) -- -
io_wait_timeout
(Numeric
) -- -
exit_timeout
(Numeric
) --
Parameters:
-
opts
(Hash
) -- -
cmd
(String
) --
def run_command(cmd, opts = {}) command = prepare_command(cmd, opts) unless command.interactive? raise NotImplementedError, "Running interactively is not supported with this process launcher." end start_command(command) block_given? ? yield(command) : command end
def run_command_and_stop(cmd, opts = {})
(**opts)
-
:io_wait_timeout
(Numeric
) -- -
:exit_timeout
(Numeric
) -- -
:fail_on_error
(Boolean
) --
Parameters:
-
opts
(Hash
) -- -
cmd
(String
) --
def run_command_and_stop(cmd, opts = {}) fail_on_error = if opts.key?(:fail_on_error) opts.delete(:fail_on_error) == true else true end command = prepare_command(cmd, opts) start_command(command) command.stop return unless fail_on_error begin expect(command).to have_finished_in_time expect(command).to be_successfully_executed rescue ::RSpec::Expectations::ExpectationNotMetError => e aruba.announcer.activate(aruba.config.activate_announcer_on_command_failure) aruba.event_bus.notify Events::CommandStopped.new(command) raise e end end
def start_command(command)
def start_command(command) aruba.config.run_before_hook(:command, self, command) in_current_directory do command.start end stop_signal = command.stop_signal aruba.announcer.announce(:stop_signal, command.pid, stop_signal) if stop_signal aruba.config.run_after_hook(:command, self, command) end
def stop_all_commands(&block)
- Yield: -
def stop_all_commands(&block) cmds = if block all_commands.select(&block) else all_commands end cmds.each(&:stop) self end
def terminate_all_commands(&block)
- Yield: -
def terminate_all_commands(&block) cmds = if block all_commands.select(&block) else all_commands end cmds.each(&:terminate) self end
def type(input)
-
input
(String
) --
def type(input) return close_input if input == "\u0004" last_command_started.write(input << "\n") end
def which(program, path = nil)
-
path
(String
) -- -
program
(#to_s
) --
def which(program, path = nil) with_environment do # ENV is set within this block path = ENV["PATH"] if path.nil? Aruba.platform.which(program, path) end end