Class: MultiRepo::PopenRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/multirepo/utility/popen-runner.rb

Class Method Summary collapse

Class Method Details

.run(cmd, verbosity) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/multirepo/utility/popen-runner.rb', line 7

def self.run(cmd, verbosity)
  Console.log_info("Command: #{cmd}") if Config.instance.verbose
  
  lines = []
  last_command_succeeded = false
  Open3.popen2e(cmd) do |_stdin, stdout_and_stderr, thread|
    stdout_and_stderr.each do |line|
      print line if Config.instance.verbose
      lines << line
    end
    last_command_succeeded = thread.value.success?
  end
  
  output = lines.join("").rstrip
  
  Console.log_error(output) if !last_command_succeeded && verbosity == Verbosity::OUTPUT_ON_ERROR
  
  return output, last_command_succeeded
end