Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions lib/gitx/extensions/thor.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
require 'English'
require 'open3'

class Thor
module Actions
# execute a shell command and raise an error if non-zero exit code is returned
# return the string output from the command
def run_cmd(cmd, options = {})
say "$ #{cmd}"
output = `#{cmd}`
success = $CHILD_STATUS.to_i == 0
fail "#{cmd} failed" unless success || options[:allow_failure]
def run_cmd(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
cmd = args
say "$ #{cmd.join(' ')}", :yellow
output = ''

Open3.popen2e(*cmd) do |stdin, stdout_err, wait_thr|
while line = stdout_err.gets
say line, :yellow
output << line
end

exit_status = wait_thr.value
fail "#{cmd.join(' ')} failed" unless exit_status.success? || options[:allow_failure]
end
output
end

Expand Down
2 changes: 1 addition & 1 deletion lib/gitx/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Gitx
VERSION = '2.21.1'
VERSION = '2.21.2'
end