Sha256: 63569c87e4388e173018831ca7ed84e6c704a494ee68733e11f51e1eebe319e7

Contents?: true

Size: 761 Bytes

Versions: 13

Compression:

Stored size: 761 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

13 entries across 13 versions & 1 rubygems

Version Path
gitx-3.1.0.ci.216.1 lib/gitx/executor.rb
gitx-3.1.0 lib/gitx/executor.rb
gitx-3.0.2.ci.213.1 lib/gitx/executor.rb
gitx-3.0.2.ci.207.1 lib/gitx/executor.rb
gitx-3.0.2 lib/gitx/executor.rb
gitx-3.0.1.ci.200.1 lib/gitx/executor.rb
gitx-3.0.1 lib/gitx/executor.rb
gitx-3.0.0.ci.188.1 lib/gitx/executor.rb
gitx-3.0.0 lib/gitx/executor.rb
gitx-2.23.2.ci.182.1 lib/gitx/executor.rb
gitx-2.23.2 lib/gitx/executor.rb
gitx-2.23.1.ci.174.1 lib/gitx/executor.rb
gitx-2.23.1 lib/gitx/executor.rb