Class: Aruba::CommandMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/command_monitor.rb

Overview

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

Defined Under Namespace

Classes: DefaultLastCommandStarted, DefaultLastCommandStopped

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CommandMonitor

rubocop:disable Metrics/MethodLength



38
39
40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#last_command_startedObject

Returns the value of attribute last_command_started.



15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def last_command_started
  @last_command_started
end

#last_command_stoppedObject

Return the last command stopped



51
52
53
54
55
56
57
# 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

#registered_commandsObject (readonly)

Returns the value of attribute registered_commands.



15
16
17
# File 'lib/aruba/platforms/command_monitor.rb', line 15

def registered_commands
  @registered_commands
end

Instance Method Details

#all_outputString

Deprecated.

Get stderr and stdout of all commands

Returns:

  • (String)

    The stderr and stdout of all command which have run before



168
169
170
# File 'lib/aruba/platforms/command_monitor.rb', line 168

def all_output
  all_stdout << all_stderr
end

#all_stderrString

Deprecated.

Get stderr of all commands

Returns:

  • (String)

    The stderr of all command which have run before



151
152
153
154
155
156
157
158
159
160
161
# 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_stdoutString

Deprecated.

Get stdout of all commands

Returns:

  • (String)

    The stdout of all command which have run before



134
135
136
137
138
139
140
141
142
143
144
# 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

#clearObject

Clear list of known commands



92
93
94
95
96
97
# File 'lib/aruba/platforms/command_monitor.rb', line 92

def clear
  registered_commands.each(&:terminate)
  registered_commands.clear

  self
end

#find(cmd) {|Command| ... } ⇒ Object

Find command

Yields:

  • (Command)

    This yields the found command



82
83
84
85
86
87
88
89
# 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) ⇒ Object

Deprecated.

Raises:

  • (ArgumentError)


215
216
217
218
219
220
# 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_exit_statusObject

Deprecated.


173
174
175
176
177
178
179
# 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_processesObject

Deprecated.


208
209
210
211
212
# 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) ⇒ Object

Deprecated.

Fetch output (stdout, stderr) from command

Parameters:

  • cmd (String)

    The command



104
105
106
107
# 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) ⇒ Object

Register command to monitor



223
224
225
226
227
# File 'lib/aruba/platforms/command_monitor.rb', line 223

def register_command(cmd)
  registered_commands << cmd

  self
end

#stderr_from(cmd) ⇒ Object

Deprecated.

Fetch stderr from command

Parameters:

  • cmd (String)

    The command



124
125
126
127
# 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) ⇒ Object

Deprecated.

Fetch stdout from command

Parameters:

  • cmd (String)

    The command



114
115
116
117
# 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) ⇒ Object

Deprecated.


182
183
184
185
# 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!Object

Deprecated.


193
194
195
196
197
# 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) ⇒ Object

Deprecated.


188
189
190
# File 'lib/aruba/platforms/command_monitor.rb', line 188

def terminate_process!(process)
  process.terminate
end

#terminate_processesObject

Deprecated.

Terminate all running processes



201
202
203
204
205
# 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