class Aruba::CommandMonitor

The command monitor is part of the private API of Aruba.

@private

Attributes

last_command_started[R]
registered_commands[R]

Public Class Methods

new(opts = {}) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/aruba/platforms/command_monitor.rb, line 38
def initialize(opts = {})
  @registered_commands = []
  @announcer = opts.fetch(:announcer)

  @last_command_stopped = DefaultLastCommandStopped.new
  @last_command_started = DefaultLastCommandStarted.new

rescue KeyError => e
  raise ArgumentError, e.message
end

Public Instance Methods

all_output() click to toggle source

@deprecated Get stderr and stdout of all commands

@return [String]

The stderr and stdout of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 168
def all_output
  all_stdout << all_stderr
end
all_stderr() click to toggle source

@deprecated Get stderr of all commands

@return [String]

The stderr of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 151
def all_stderr
  registered_commands.each(&:stop)

  if RUBY_VERSION < '1.9.3'
    # rubocop:disable Style/EachWithObject
    registered_commands.inject("") { |a, e| a << e.stderr; a }
    # rubocop:enable Style/EachWithObject
  else
    registered_commands.each_with_object("") { |e, a| a << e.stderr }
  end
end
all_stdout() click to toggle source

@deprecated Get stdout of all commands

@return [String]

The stdout of all command which have run before
# File lib/aruba/platforms/command_monitor.rb, line 134
def all_stdout
  registered_commands.each(&:stop)

  if RUBY_VERSION < '1.9.3'
    # rubocop:disable Style/EachWithObject
    registered_commands.inject("") { |a, e| a << e.stdout; a }
    # rubocop:enable Style/EachWithObject
  else
    registered_commands.each_with_object("") { |e, a| a << e.stdout }
  end
end
clear() click to toggle source

Clear list of known commands

# File lib/aruba/platforms/command_monitor.rb, line 92
def clear
  registered_commands.each(&:terminate)
  registered_commands.clear

  self
end
find(cmd) click to toggle source

Find command

@yield [Command]

This yields the found command
# File lib/aruba/platforms/command_monitor.rb, line 82
def find(cmd)
  cmd = cmd.commandline if cmd.respond_to? :commandline
  command = registered_commands.reverse.find { |c| c.commandline == cmd }

  fail CommandNotFoundError, "No command named '#{cmd}' has been started" if command.nil?

  command
end
get_process(wanted) click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 215
def get_process(wanted)
  command = find(wanted)
  raise ArgumentError.new("No process named '#{wanted}' has been started") unless command

  command
end
last_command_started=(cmd) click to toggle source

Set last command started

@param [String] cmd

The commandline of the command
# File lib/aruba/platforms/command_monitor.rb, line 66
def last_command_started=(cmd)
  @last_command_started = find(cmd)
end
last_command_stopped() click to toggle source

Return the last command stopped

# File lib/aruba/platforms/command_monitor.rb, line 51
def last_command_stopped
  return @last_command_stopped unless @last_command_stopped.nil?

  registered_commands.each(&:stop)

  @last_command_stopped
end
last_command_stopped=(cmd) click to toggle source

Set last command started

@param [String] cmd

The commandline of the command
# File lib/aruba/platforms/command_monitor.rb, line 74
def last_command_stopped=(cmd)
  @last_command_stopped = find(cmd)
end
last_exit_status() click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 173
def last_exit_status
  Aruba.platform.deprecated('The use of "#last_exit_status" is deprecated. Use "last_command_(started|stopped).exit_status" instead')

  return @last_exit_status if @last_exit_status
  registered_commands.each(&:stop)
  @last_exit_status
end
only_processes() click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 208
def only_processes
  Aruba.platform.deprecated('The use of "#only_processes" is deprecated.')

  registered_commands
end
output_from(cmd) click to toggle source

@deprecated Fetch output (stdout, stderr) from command

@param [String] cmd

The command
# File lib/aruba/platforms/command_monitor.rb, line 104
def output_from(cmd)
  cmd = Utils.detect_ruby(cmd)
  find(cmd).output
end
register_command(cmd) click to toggle source

Register command to monitor

# File lib/aruba/platforms/command_monitor.rb, line 223
def register_command(cmd)
  registered_commands << cmd

  self
end
stderr_from(cmd) click to toggle source

@deprecated Fetch stderr from command

@param [String] cmd

The command
# File lib/aruba/platforms/command_monitor.rb, line 124
def stderr_from(cmd)
  cmd = Utils.detect_ruby(cmd)
  find(cmd).stderr
end
stdout_from(cmd) click to toggle source

@deprecated Fetch stdout from command

@param [String] cmd

The command
# File lib/aruba/platforms/command_monitor.rb, line 114
def stdout_from(cmd)
  cmd = Utils.detect_ruby(cmd)
  find(cmd).stdout
end
stop_process(process) click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 182
def stop_process(process)
  @last_command_stopped = process
  @last_exit_status     = process.stop(announcer)
end
stop_processes!() click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 193
def stop_processes!
  Aruba.platform.deprecated('The use of "#stop_processes!" is deprecated.')

  registered_commands.each(&:stop)
end
terminate_process!(process) click to toggle source

@deprecated

# File lib/aruba/platforms/command_monitor.rb, line 188
def terminate_process!(process)
  process.terminate
end
terminate_processes() click to toggle source

@deprecated Terminate all running processes

# File lib/aruba/platforms/command_monitor.rb, line 201
def terminate_processes
  Aruba.platform.deprecated('The use of "#terminate_processes" is deprecated.')

  registered_commands.each(&:terminate)
end