diff options
-rw-r--r-- | _support/run.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/_support/run.rb b/_support/run.rb index 8d6ea482e..121729b32 100644 --- a/_support/run.rb +++ b/_support/run.rb @@ -1,7 +1,29 @@ def run!(cmd, chdir='.') - print_cmd = cmd.join(' ') - puts "-> #{print_cmd}" + GitalySupport.print_cmd(cmd) if !system(*cmd, chdir: chdir) - abort "command failed: #{print_cmd}" + GitalySupport.fail_cmd!(cmd) + end +end + +def capture!(cmd, chdir='.') + GitalySupport.print_cmd(cmd) + output = IO.popen(cmd, chdir: chdir) { |io| io.read } + fail_cmd!(cmd) unless $?.success? + output +end + +module GitalySupport + class << self + def print_cmd(cmd) + puts '-> ' + printable_cmd(cmd) + end + + def fail_cmd!(cmd) + abort "command failed: #{printable_cmd(cmd)}" + end + + def printable_cmd(cmd) + cmd.join(' ') + end end end |