lib/carrasco/thor.rb in carrasco-0.1.5 vs lib/carrasco/thor.rb in carrasco-0.1.6
- old
+ new
@@ -1,9 +1,11 @@
require "thor"
module Carrasco
class Thor < ::Thor
+ CommandFailed = Class.new(StandardError)
+
no_commands do
def execute_command(command)
command_executer.execute!(command)
end
@@ -11,9 +13,38 @@
@@command_executer = command_executer
end
def command_executer
@@command_executer ||= CommandExecuter.new
+ end
+
+ def execute_commands(commands, break_on_failure)
+ if break_on_failure
+ return execute_with_break_on_failure(commands)
+ end
+
+ errors = []
+
+ commands.each do |command|
+ begin
+ send(command)
+ rescue StandardError => e
+ errors << e.message
+ end
+ end
+
+ unless errors.empty?
+ messages = errors.map {|e| "'#{e}'"}
+ raise CommandFailed, "Failed with messages: #{messages.join(', ')}"
+ end
+ end
+
+ private
+
+ def execute_with_break_on_failure(commands)
+ commands.each do |command|
+ send(command)
+ end
end
end
end
end