Module: GitCurate::Util

Defined in:
lib/git_curate/util.rb

Class Method Summary collapse

Class Method Details

.command_output(command) ⇒ Object

Runs the passed string as a system command and returns its output. If the command doesn’t exit with 0 (success), then an error will be thrown, with the error output as its message.



16
17
18
19
20
21
22
23
24
25
# File 'lib/git_curate/util.rb', line 16

def self.command_output(command)
  stdout_str, stderr_str, status = Open3.capture3(command)
  exit_status = status.exitstatus

  if exit_status != EXIT_SUCCESS
    raise SystemCommandError.new(stderr_str, exit_status)
  end

  stdout_str
end

.command_to_a(command) ⇒ Object

Runs the passed string as a system command, gathers any lines of output, stripped of leading and trailing whitespace, and returns them as an array.



9
10
11
# File 'lib/git_curate/util.rb', line 9

def self.command_to_a(command)
  command_output(command).split($/).map(&:strip)
end