Sha256: 026e60a588b38ed71807092ce2ca4e49054b6caeb63d7590334bc4d894f9a0bd

Contents?: true

Size: 729 Bytes

Versions: 1

Compression:

Stored size: 729 Bytes

Contents

require "open3"

module GitCurate

  module Util

    # 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.
    def self.command_to_a(command)
      command_output(command).split($/).map(&:strip)
    end

    # 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.
    def self.command_output(command)
      stdout_str, stderr_str, status = Open3.capture3(command)

      if status.exitstatus != 0
        raise RuntimeError.new(stderr_str)
      end

      stdout_str
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_curate-0.7.1 lib/git_curate/util.rb