Skip to content

Commit

Permalink
rich error
Browse files Browse the repository at this point in the history
  • Loading branch information
bmizerany committed Nov 9, 2009
1 parent e7db633 commit 0dcf4a0
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/guns.rb
Expand Up @@ -50,9 +50,21 @@ def sh(cmd, *args)
module_function :sh

def sh!(cmd, *args)
out, err, code = sh(cmd, *args)
cmd << " " << args.join(" ") if !args.empty?
raise Failure, "(#{cmd})\n#{err}" if code != 0
env = args.pop if args.last.kind_of?(Hash)
env ||= {}
out, err, code = sh(cmd, *(args + [env]))
if code != 0
cmd << " " << args.join(" ") if !args.empty?
said = []
said << out if !out.empty?
said << err if !err.empty?
said = said.join "\n"
if !env.empty?
envs = env.map {|a| a * "=" }.join(" ")
cmd = envs << " " << cmd
end
raise Failure, "(#{cmd})\n#{said}}"
end
[out, err, code]
end
module_function :sh!
Expand Down

0 comments on commit 0dcf4a0

Please sign in to comment.