lib/devinstall/utils.rb in devinstall-1.0.0 vs lib/devinstall/utils.rb in devinstall-1.0.1

- old
+ new

@@ -1,29 +1,36 @@ module Utils + class CommandError < RuntimeError + attr_accessor :command_output, :return_code + def verbose_message + if $verbose + puts self.message + puts '#'*20 + puts self.command_output + puts '#'*20 + puts "Exit code: #{self.return_code}" + end + end + end + def command(cmd) puts cmd if $verbose ret='' unless $dry - ret = `#{cmd}` unless $dry + ret = `#{cmd}` if $?.exitstatus != 0 ## return failure - puts "While executing:" - puts cmd - puts "The command failed with exitstatus #{$?.exitstatus}" - puts "Full output of command follows" - puts "="*40 - puts ret - puts "="*40 - puts "Nothing to do. Aborting!" - exit! "Done" + err=CommandError.new "ErrorRunning #{cmd}" + err.command_output = ret + err.return_code = $?.exitstatus + raise err end end ret end - def exit! msg - puts msg || "Aborting!" + def exit!(msg=nil) + puts msg || 'Aborting!' Kernel.exit 1 end - end #module