From 3fdf1e1e1bfbb87c31f9b031726fac5d9420cfec Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Sat, 1 Sep 2007 02:10:45 +0000 Subject: [PATCH] Add a "match" remote dependency method (closes #9379) git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@7386 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- CHANGELOG | 2 ++ .../recipes/deploy/remote_dependency.rb | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index ac770e22..fe4c95d2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add a "match" remote dependency method [Adam Greene] + * Allow auth-caching of subversion credentials to be enabled via :scm_auth_cache [tsmith] * Don't let a task trigger itself when used as the source for an "on" hook [Jamis Buck] diff --git a/lib/capistrano/recipes/deploy/remote_dependency.rb b/lib/capistrano/recipes/deploy/remote_dependency.rb index 208c0bea..ebd54495 100644 --- a/lib/capistrano/recipes/deploy/remote_dependency.rb +++ b/lib/capistrano/recipes/deploy/remote_dependency.rb @@ -34,6 +34,36 @@ module Capistrano self end + def match(command, expect, options={}) + expect = Regexp.new(Regexp.escape(expect.to_s)) unless expect.is_a?(Regexp) + + output_per_server = {} + try("#{command} ", options) do |ch, stream, out| + output_per_server[ch[:server]] ||= '' + output_per_server[ch[:server]] += out + end + + # It is possible for some of these commands to return a status != 0 + # (for example, rake --version exits with a 1). For this check we + # just care if the output matches, so we reset the success flag. + @success = true + + errored_hosts = [] + output_per_server.each_pair do |server, output| + next if output =~ expect + errored_hosts << server + end + + if errored_hosts.any? + @hosts = errored_hosts.join(', ') + output = output_per_server[errored_hosts.first] + @message = "the output #{output.inspect} from #{command.inspect} did not match #{expect.inspect}" + @success = false + end + + self + end + def or(message) @message = message self @@ -55,6 +85,7 @@ module Capistrano return unless @success # short-circuit evaluation configuration.run(command, options) do |ch,stream,out| warn "#{ch[:server]}: #{out}" if stream == :err + yield ch, stream, out if block_given? end rescue Capistrano::CommandError => e @success = false