0
@@ -9,17 +9,27 @@ module Capistrano
0
+ attr_reader :configuration
0
attr_accessor :command, :callback
0
- def initialize(command,
callback)
0
+ def initialize(command,
options, callback)
0
@command = command.strip.gsub(/\r?\n/, "\\\n")
0
@callback = callback || Capistrano::Configuration.default_io_proc
0
@@ -37,38 +47,83 @@ module Capistrano
0
- class PatternBranch < Branch
0
- attr_accessor :pattern
0
+ class ConditionBranch < Branch
0
+ attr_accessor :configuration
0
+ attr_accessor :condition
0
+ attr_reader :configuration, :condition, :server
0
+ def initialize(config, condition, server)
0
+ @configuration = config
0
+ @condition = condition
0
+ configuration.roles[role].include?(server)
0
+ eval(condition, binding)
0
+ def method_missing(sym, *args, &block)
0
+ if server.respond_to?(sym)
0
+ server.send(sym, *args, &block)
0
+ elsif configuration.respond_to?(sym)
0
+ configuration.send(sym, *args, &block)
0
- def initialize(pattern, command, callback)
0
- super(command, callback)
0
+ def initialize(configuration, condition, command, options, callback)
0
+ @configuration = configuration
0
+ @condition = condition
0
+ super(command, options, callback)
0
-
pattern === server.host
0
+
Evaluator.new(configuration, condition, server).result
0
- "#{
pattern.inspect} :: #{command.inspect}"
0
+ "#{
condition.inspect} :: #{command.inspect}"
0
+ def initialize(config)
0
+ @configuration = config
0
yield self if block_given?
0
- def if(pattern, command, &block)
0
- branches << PatternBranch.new(pattern, command, block)
0
+ def when(condition, command, options={}, &block)
0
+ branches << ConditionBranch.new(configuration, condition, command, options, block)
0
def else(command, &block)
0
-
branches << Branch.new(command, block)
0
+
@fallback = Branch.new(command, {}, block)
0
- def branch_for(server)
0
- branches.detect { |branch| branch.match(server) }
0
+ def branches_for(server)
0
+ matches = branches.select do |branch|
0
+ success = !seen_last && !branch.skip? && branch.match(server)
0
+ seen_last = success && branch.last?
0
+ matches << fallback if matches.empty? && fallback
0
+ branches.each { |branch| yield branch }
0
+ yield fallback if fallback
0
@@ -131,58 +186,57 @@ module Capistrano
0
sessions.map do |session|
0
server = session.xserver
0
- branch = tree.branch_for(server)
0
- session.open_channel do |channel|
0
- channel[:server] = server
0
- channel[:host] = server.host
0
- channel[:options] = options
0
- channel[:branch] = branch
0
- request_pty_if_necessary(channel) do |ch, success|
0
- logger.trace "executing command", ch[:server] if logger
0
- cmd = replace_placeholders(channel[:branch].command, ch)
0
- if options[:shell] == false
0
+ tree.branches_for(server).map do |branch|
0
+ session.open_channel do |channel|
0
+ channel[:server] = server
0
+ channel[:host] = server.host
0
+ channel[:options] = options
0
+ channel[:branch] = branch
0
+ request_pty_if_necessary(channel) do |ch, success|
0
+ logger.trace "executing command", ch[:server] if logger
0
+ cmd = replace_placeholders(channel[:branch].command, ch)
0
+ if options[:shell] == false
0
+ shell = "#{options[:shell] || "sh"} -c"
0
+ cmd = cmd.gsub(/[$\\`"]/) { |m| "\\#{m}" }
0
+ command_line = [environment, shell, cmd].compact.join(" ")
0
+ ch.send_data(options[:data]) if options[:data]
0
- shell = "#{options[:shell] || "sh"} -c"
0
- cmd = cmd.gsub(/[$\\`"]/) { |m| "\\#{m}" }
0
+ # just log it, don't actually raise an exception, since the
0
+ # process method will see that the status is not zero and will
0
+ # raise an exception then.
0
+ logger.important "could not open channel", ch[:server] if logger
0
- command_line = [environment, shell, cmd].compact.join(" ")
0
- ch.send_data(options[:data]) if options[:data]
0
- # just log it, don't actually raise an exception, since the
0
- # process method will see that the status is not zero and will
0
- # raise an exception then.
0
- logger.important "could not open channel", ch[:server] if logger
0
- channel.on_data do |ch, data|
0
- ch[:branch].callback[ch, :out, data]
0
+ channel.on_data do |ch, data|
0
+ ch[:branch].callback[ch, :out, data]
0
- channel.on_extended_data do |ch, type, data|
0
- ch[:branch].callback[ch, :err, data]
0
+ channel.on_extended_data do |ch, type, data|
0
+ ch[:branch].callback[ch, :err, data]
0
- channel.on_request("exit-status") do |ch, data|
0
- ch[:status] = data.read_long
0
+ channel.on_request("exit-status") do |ch, data|
0
+ ch[:status] = data.read_long
0
- channel.on_close do |ch|
0
+ channel.on_close do |ch|
0
def request_pty_if_necessary(channel)
Comments
No one has commented yet.