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
49 50 51 |
# File 'lib/aruba/api/commands.rb', line 49 def all_commands aruba.command_monitor.registered_commands end |
#all_output ⇒ String
Get stderr and stdout of all processes
117 118 119 |
# File 'lib/aruba/api/commands.rb', line 117 def all_output aruba.command_monitor.all_output end |
#all_stderr ⇒ String
Get stderr of all processes
109 110 111 |
# File 'lib/aruba/api/commands.rb', line 109 def all_stderr aruba.command_monitor.all_stderr end |
#all_stdout ⇒ String
Get stdout of all processes
101 102 103 |
# File 'lib/aruba/api/commands.rb', line 101 def all_stdout aruba.command_monitor.all_stdout end |
#close_input ⇒ Object
Close stdin
219 220 221 |
# File 'lib/aruba/api/commands.rb', line 219 def close_input last_command_started.close_io(:stdin) end |
#find_command(commandline) ⇒ Object
Find a started command
125 126 127 |
# File 'lib/aruba/api/commands.rb', line 125 def find_command(commandline) aruba.command_monitor.find(commandline) end |
#last_command_started ⇒ Object
Last command started
54 55 56 |
# File 'lib/aruba/api/commands.rb', line 54 def last_command_started aruba.command_monitor.last_command_started end |
#last_command_stopped ⇒ Object
Last command stopped
59 60 61 |
# File 'lib/aruba/api/commands.rb', line 59 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 |
# File 'lib/aruba/api/commands.rb', line 37 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
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/aruba/api/commands.rb', line 152 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.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/aruba/api/commands.rb', line 185 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
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/aruba/api/commands.rb', line 68 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
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/aruba/api/commands.rb', line 85 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
212 213 214 215 216 |
# File 'lib/aruba/api/commands.rb', line 212 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 |