lib/mattock/command-line.rb in mattock-0.1.0 vs lib/mattock/command-line.rb in mattock-0.1.1

- old
+ new

@@ -1,8 +1,9 @@ module Mattock class CommandRunResult - def initialize(status, streams) + def initialize(command, status, streams) + @command = command @process_status = status @streams = streams end attr_reader :process_status, :streams @@ -29,11 +30,11 @@ def must_succeed! case exit_code when 0 return exit_code else - fail "Command '#{name}' failed with exit status #{$?.exitstatus}: \n" + fail "Command #{@command.inspect} failed with exit status #{$?.exitstatus}: \n#{streams.inspect}" end end end class CommandLine @@ -44,10 +45,14 @@ yield self if block_given? end attr_accessor :name, :executable, :options + def verbose + Rake.verbose && Rake.verbose != Rake::FileUtilsExt::DEFAULT + end + def name @name || executable end def command @@ -80,21 +85,21 @@ def self.execute(command) pipe = IO.popen(command) pid = pipe.pid pid, status = Process.wait2(pid) - result = CommandRunResult.new(status, {1 => pipe.read}) + result = CommandRunResult.new(command, status, {1 => pipe.read}) pipe.close return result end def run - print command + " " if $verbose + print command + " " if verbose result = self.class.execute(command) - print "=> #{result.exit_code}" if $verbose + print "=> #{result.exit_code}" if verbose return result ensure - puts if $verbose + puts if verbose end def succeeds? run.succeeded? end