module GitCurate::Util

Public Class Methods

command_output(command) click to toggle source

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.

# 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) click to toggle source

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.

# File lib/git_curate/util.rb, line 9
def self.command_to_a(command)
  command_output(command).split($/).map(&:strip)
end