Module: CodeownerValidator::Command
Overview
Public: Module utilized for housing the interactions with the terminal
Instance Method Summary collapse
-
#run(*args, log: true) ⇒ Object
Executes system commands.
Methods included from Logging
#log_command, #log_error, #log_info, #log_stderr, #log_verbose, #log_warn, #logger, #program_name
Instance Method Details
#run(*args, log: true) ⇒ Object
Executes system commands
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/codeowner_validator/common/command.rb', line 12 def run(*args, log: true) output = [] status = nil log_command(*args) if log Open3.popen2e(*args) do |_stdin, stdout_and_stderr, wait_thr| until (line = stdout_and_stderr.gets).nil? output.push line log_info line.chop end status = wait_thr.value end return if status.success? = [].tap do |ar| ar << "Status: #{status.exitstatus}" # because some commands contain sensitive information (ie passwords), # may not want to display the actual command ar << "Command: #{args.join(' ')}" if log end log_error .join(', ') raise .join(', ') end |