Module: Aruba::Api::Commands
- Included in:
- Aruba::Api
- Defined in:
- lib/aruba/api/commands.rb
Overview
Command module
Instance Method Summary collapse
-
#all_commands ⇒ Array
Return all commands.
-
#all_output ⇒ String
Get stderr and stdout of all processes.
-
#all_stderr ⇒ String
Get stderr of all processes.
-
#all_stdout ⇒ String
Get stdout of all processes.
-
#close_input ⇒ Object
Close stdin.
-
#find_command(commandline) ⇒ Object
Find a started command.
-
#last_command_started ⇒ Object
Last command started.
-
#last_command_stopped ⇒ Object
Last command stopped.
-
#pipe_in_file(file_name) ⇒ Object
Pipe data in file.
-
#run_command(cmd, opts = {}) {|SpawnProcess| ... } ⇒ Object
Run given command and stop it if timeout is reached.
-
#run_command_and_stop(cmd, opts = {}) ⇒ Object
Run a command with aruba.
-
#stop_all_commands {|Command| ... } ⇒ Object
Stop all commands.
-
#terminate_all_commands {|Command| ... } ⇒ Object
Terminate all commands.
-
#type(input) ⇒ Object
Provide data to command via stdin.
-
#which(program, path = nil) ⇒ Object
Resolve path for command using the PATH-environment variable.
Instance Method Details
#all_commands ⇒ Array
Return all commands
47 48 49 |
# File 'lib/aruba/api/commands.rb', line 47 def all_commands aruba.command_monitor.registered_commands end |
#all_output ⇒ String
Get stderr and stdout of all processes
115 116 117 |
# File 'lib/aruba/api/commands.rb', line 115 def all_output aruba.command_monitor.all_output end |
#all_stderr ⇒ String
Get stderr of all processes
107 108 109 |
# File 'lib/aruba/api/commands.rb', line 107 def all_stderr aruba.command_monitor.all_stderr end |
#all_stdout ⇒ String
Get stdout of all processes
99 100 101 |
# File 'lib/aruba/api/commands.rb', line 99 def all_stdout aruba.command_monitor.all_stdout end |
#close_input ⇒ Object
Close stdin
217 218 219 |
# File 'lib/aruba/api/commands.rb', line 217 def close_input last_command_started.close_io(:stdin) end |
#find_command(commandline) ⇒ Object
Find a started command
123 124 125 |
# File 'lib/aruba/api/commands.rb', line 123 def find_command(commandline) aruba.command_monitor.find(commandline) end |
#last_command_started ⇒ Object
Last command started
52 53 54 |
# File 'lib/aruba/api/commands.rb', line 52 def last_command_started aruba.command_monitor.last_command_started end |
#last_command_stopped ⇒ Object
Last command stopped
57 58 59 |
# File 'lib/aruba/api/commands.rb', line 57 def last_command_stopped aruba.command_monitor.last_command_stopped end |
#pipe_in_file(file_name) ⇒ Object
Pipe data in file
35 36 37 38 39 40 41 |
# File 'lib/aruba/api/commands.rb', line 35 def pipe_in_file(file_name) file_name = (file_name) File.open(file_name, "r").each_line do |line| last_command_started.write(line) end end |
#run_command(cmd, opts = {}) {|SpawnProcess| ... } ⇒ Object
Run given command and stop it if timeout is reached
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/aruba/api/commands.rb', line 150 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 |
#run_command_and_stop(cmd, opts = {}) ⇒ Object
Run a command with aruba
Checks for error during command execution and checks the output to detect an timeout error.
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/aruba/api/commands.rb', line 183 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 |
#stop_all_commands {|Command| ... } ⇒ Object
Stop all commands
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aruba/api/commands.rb', line 66 def stop_all_commands(&block) cmds = if block all_commands.select(&block) else all_commands end cmds.each(&:stop) self end |
#terminate_all_commands {|Command| ... } ⇒ Object
Terminate all commands
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/aruba/api/commands.rb', line 83 def terminate_all_commands(&block) cmds = if block all_commands.select(&block) else all_commands end cmds.each(&:terminate) self end |
#type(input) ⇒ Object
Provide data to command via stdin
210 211 212 213 214 |
# File 'lib/aruba/api/commands.rb', line 210 def type(input) return close_input if input == "\u0004" last_command_started.write(input << "\n") end |
#which(program, path = nil) ⇒ Object
Resolve path for command using the PATH-environment variable
22 23 24 25 26 27 28 29 |
# File 'lib/aruba/api/commands.rb', line 22 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 |