Class: Gitx::Executor
- Inherits:
-
Object
- Object
- Gitx::Executor
- Defined in:
- lib/gitx/executor.rb
Constant Summary collapse
- ExecutionError =
Class.new(StandardError)
Instance Method Summary collapse
-
#execute(*cmd) {|"$ #{cmd.join(' ')}"| ... } ⇒ Object
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.
Instance Method Details
#execute(*cmd) {|"$ #{cmd.join(' ')}"| ... } ⇒ Object
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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gitx/executor.rb', line 10 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 |