1def run!(cmd, chdir='.') 2 GitalySupport.print_cmd(cmd) 3 unless system(*cmd, chdir: chdir) 4 GitalySupport.fail_cmd!(cmd) 5 end 6end 7 8def run2!(cmd, chdir: '.', out: 1) 9 GitalySupport.print_cmd(cmd) 10 unless system(*cmd, chdir: chdir, out: out) 11 GitalySupport.fail_cmd!(cmd) 12 end 13end 14 15def capture!(cmd, chdir='.') 16 GitalySupport.print_cmd(cmd) 17 output = IO.popen(cmd, chdir: chdir) { |io| io.read } 18 GitalySupport.fail_cmd!(cmd) unless $?.success? 19 output 20end 21 22module GitalySupport 23 class << self 24 def print_cmd(cmd) 25 puts '-> ' + printable_cmd(cmd) 26 end 27 28 def fail_cmd!(cmd) 29 abort "command failed: #{printable_cmd(cmd)}" 30 end 31 32 def printable_cmd(cmd) 33 cmd.join(' ') 34 end 35 end 36end 37