Sha256: 955c69c9c0ee2be2e2e6ec2d1fcbccd4b880e9e0b4998035b8bc95f25c7fa2cf

Contents?: true

Size: 762 Bytes

Versions: 11

Compression:

Stored size: 762 Bytes

Contents

require 'open3'

module Gitx
  class Executor
    ExecutionError = Class.new(StandardError)

    # execute a shell command and raise an error if non-zero exit code is returned
    # return the string output from the command
    # block argument is passed all output from the executed thread
    def execute(*cmd)
      yield "$ #{cmd.join(' ')}" if block_given?
      output = ''

      Open3.popen2e(*cmd) do |_stdin, stdout_err, wait_thread|
        loop do
          line = stdout_err.gets
          break unless line

          output << line
          yield line if block_given?
        end

        exit_status = wait_thread.value
        raise ExecutionError, "#{cmd.join(' ')} failed" unless exit_status.success?
      end
      output
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
gitx-4.5.0 lib/gitx/executor.rb
gitx-4.4.0 lib/gitx/executor.rb
gitx-4.3.0 lib/gitx/executor.rb
gitx-4.1.1 lib/gitx/executor.rb
gitx-4.1.0 lib/gitx/executor.rb
gitx-4.0.0 lib/gitx/executor.rb
gitx-4.0.0.ci.234.1 lib/gitx/executor.rb
gitx-3.2.0 lib/gitx/executor.rb
gitx-3.2.0.ci.231.1 lib/gitx/executor.rb
gitx-3.1.2 lib/gitx/executor.rb
gitx-3.1.1 lib/gitx/executor.rb