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
50 51 52 |
# File 'lib/aruba/api/commands.rb', line 50 def all_commands aruba.command_monitor.registered_commands end |
#all_output ⇒ String
Get stderr and stdout of all processes
118 119 120 |
# File 'lib/aruba/api/commands.rb', line 118 def all_output aruba.command_monitor.all_output end |
#all_stderr ⇒ String
Get stderr of all processes
110 111 112 |
# File 'lib/aruba/api/commands.rb', line 110 def all_stderr aruba.command_monitor.all_stderr end |
#all_stdout ⇒ String
Get stdout of all processes
102 103 104 |
# File 'lib/aruba/api/commands.rb', line 102 def all_stdout aruba.command_monitor.all_stdout end |
#close_input ⇒ Object
Close stdin
220 221 222 |
# File 'lib/aruba/api/commands.rb', line 220 def close_input last_command_started.close_io(:stdin) end |
#find_command(commandline) ⇒ Object
Find a started command
126 127 128 |
# File 'lib/aruba/api/commands.rb', line 126 def find_command(commandline) aruba.command_monitor.find(commandline) end |
#last_command_started ⇒ Object
Last command started
55 56 57 |
# File 'lib/aruba/api/commands.rb', line 55 def last_command_started aruba.command_monitor.last_command_started end |
#last_command_stopped ⇒ Object
Last command stopped
60 61 62 |
# File 'lib/aruba/api/commands.rb', line 60 def last_command_stopped aruba.command_monitor.last_command_stopped end |
#pipe_in_file(file_name) ⇒ Object
Pipe data in file
37 38 39 40 41 42 43 44 |
# File 'lib/aruba/api/commands.rb', line 37 def pipe_in_file(file_name) file_name = (file_name) File.open(file_name, 'r') do |file| file.each_line do |line| last_command_started.write(line) end end end |
#run_command(cmd, opts = {}) {|SpawnProcess| ... } ⇒ Object
Run given command and stop it if timeout is reached
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/aruba/api/commands.rb', line 153 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.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/aruba/api/commands.rb', line 186 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
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/aruba/api/commands.rb', line 69 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
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/aruba/api/commands.rb', line 86 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
213 214 215 216 217 |
# File 'lib/aruba/api/commands.rb', line 213 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
24 25 26 27 28 29 30 31 |
# File 'lib/aruba/api/commands.rb', line 24 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 |