lib/cape/capistrano.rb in cape-1.7.0 vs lib/cape/capistrano.rb in cape-1.8.0
- old
+ new
@@ -1,8 +1,9 @@
require 'cape/rake'
require 'cape/recipe_definition'
require 'cape/util'
+require 'cape/xterm'
module Cape
# An abstraction of the Capistrano installation.
class Capistrano
@@ -103,43 +104,52 @@
block = lambda { |context|
recipe_name = name_tokens.last
if recipe_definition.rename
recipe_name = recipe_definition.rename.call(name_tokens.last)
end
- context.task recipe_name, recipe_definition.options do
- arguments = Array(task[:parameters]).collect do |a|
- if (value = ENV[a.upcase])
- value = value.inspect
+ begin
+ context.task recipe_name, recipe_definition.options do
+ arguments = Array(task[:parameters]).collect do |a|
+ if (value = ENV[a.upcase])
+ value = value.inspect
+ end
+ value
end
- value
- end
- if arguments.empty?
- arguments = nil
- else
- arguments = "[#{arguments.join ','}]"
- end
+ if arguments.empty?
+ arguments = nil
+ else
+ arguments = "[#{arguments.join ','}]"
+ end
- unless env
- env_strings = recipe_definition.env.collect do |var_name, var_value|
- if var_name.nil? || var_value.nil?
- nil
- else
- if var_value.is_a?(Proc)
- var_value = context.instance_eval do
- var_value.call
+ unless env
+ env_strings = recipe_definition.env.collect do |var_name, var_value|
+ if var_name.nil? || var_value.nil?
+ nil
+ else
+ if var_value.is_a?(Proc)
+ var_value = context.instance_eval do
+ var_value.call
+ end
end
+ "#{var_name}=#{var_value.inspect}"
end
- "#{var_name}=#{var_value.inspect}"
- end
- end.compact
- env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
- end
+ end.compact
+ env = env_strings.empty? ? nil : (' ' + env_strings.join(' '))
+ end
- path = recipe_definition.cd || context.current_path
- path = path.call if path.respond_to?(:call)
- command = "cd #{path} && #{rake.remote_executable} " +
- "#{task[:name]}#{arguments}#{env}"
- context.run command
+ path = recipe_definition.cd || context.current_path
+ path = path.call if path.respond_to?(:call)
+ command = "cd #{path} && #{rake.remote_executable} " +
+ "#{task[:name]}#{arguments}#{env}"
+ context.run command
+ end
+ rescue => e
+ $stderr.puts XTerm.bold_and_foreground_red('*** WARNING:') +
+ ' ' +
+ XTerm.bold("You must use Cape's renaming API in order " +
+ 'to mirror Rake task ') +
+ XTerm.bold_and_underlined(task[:name]) +
+ XTerm.bold(" (#{e.message})")
end
}
# Nest the recipe inside its containing namespaces.
name_tokens[0...-1].reverse.each do |namespace_token|
inner_block = block