Class: CobraCommander::Executor::MultiExec

Inherits:
Object
  • Object
show all
Defined in:
lib/cobra_commander/executor/multi_exec.rb

Overview

Executes a command on multiple components simultaniously

Instance Method Summary collapse

Constructor Details

#initialize(components) ⇒ MultiExec

Returns a new instance of MultiExec.



11
12
13
# File 'lib/cobra_commander/executor/multi_exec.rb', line 11

def initialize(components)
  @components = components
end

Instance Method Details

#run(command, output: $stdout, spin_output: $stderr, only_output_on_error: true, **cmd_options) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cobra_commander/executor/multi_exec.rb', line 15

def run(command, output: $stdout, spin_output: $stderr, only_output_on_error: true, **cmd_options)
  cmmd_output = StringIO.new
  multi = TTY::Spinner::Multi.new("Running #{command}", output: spin_output)
  @components.each do |component|
    component_exec(multi, component, command, only_output_on_error: only_output_on_error,
                                              stderr: :stdout, output: cmmd_output,
                                              **cmd_options)
  end
  multi.auto_spin
  output << cmmd_output.string
  true
end