mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Added support for start and finish callbacks, which get invoked when any task is called via the command-line
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6708 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
dee88819f3
commit
90e9dc1880
5 changed files with 29 additions and 5 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added support for start and finish callbacks, which get invoked when any task is called via the command-line [Jamis Buck]
|
||||
|
||||
* Make `capify' understand simple command-line switches [Jamis Buck]
|
||||
|
||||
* Make the server definition itself available to SSH channels, rather than just the host name [Jamis Buck]
|
||||
|
|
|
@ -36,7 +36,10 @@ module Capistrano
|
|||
|
||||
def execute_requested_actions(config)
|
||||
Array(options[:vars]).each { |name, value| config.set(name, value) }
|
||||
Array(options[:actions]).each { |action| config.find_and_execute_task(action) }
|
||||
|
||||
Array(options[:actions]).each do |action|
|
||||
config.find_and_execute_task(action, :before => :start, :after => :finish)
|
||||
end
|
||||
end
|
||||
|
||||
def set_pre_vars(config) #:nodoc:
|
||||
|
|
|
@ -85,9 +85,14 @@ module Capistrano
|
|||
# Attempts to locate the task at the given fully-qualified path, and
|
||||
# execute it. If no such task exists, a Capistrano::NoSuchTaskError will
|
||||
# be raised.
|
||||
def find_and_execute_task(path)
|
||||
def find_and_execute_task(path, hooks={})
|
||||
task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
|
||||
execute_task(task)
|
||||
|
||||
trigger(hooks[:before], task) if hooks[:before]
|
||||
result = execute_task(task)
|
||||
trigger(hooks[:after], task) if hooks[:after]
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -78,8 +78,8 @@ class CLIExecuteTest < Test::Unit::TestCase
|
|||
@cli.options[:actions] = %w(first second)
|
||||
@config.expects(:set).with(:foo, "bar")
|
||||
@config.expects(:set).with(:baz, "bang")
|
||||
@config.expects(:find_and_execute_task).with("first")
|
||||
@config.expects(:find_and_execute_task).with("second")
|
||||
@config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
|
||||
@config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
|
||||
@cli.execute!
|
||||
end
|
||||
|
||||
|
|
|
@ -127,6 +127,20 @@ class ConfigurationExecutionTest < Test::Unit::TestCase
|
|||
assert_nothing_raised { @config.find_and_execute_task("path:to:task") }
|
||||
end
|
||||
|
||||
def test_find_and_execute_task_with_before_option_should_trigger_callback
|
||||
@config.expects(:find_task).with("path:to:task").returns(:found)
|
||||
@config.expects(:trigger).with(:incoming, :found)
|
||||
@config.expects(:execute_task).with(:found)
|
||||
@config.find_and_execute_task("path:to:task", :before => :incoming)
|
||||
end
|
||||
|
||||
def test_find_and_execute_task_with_after_option_should_trigger_callback
|
||||
@config.expects(:find_task).with("path:to:task").returns(:found)
|
||||
@config.expects(:trigger).with(:outgoing, :found)
|
||||
@config.expects(:execute_task).with(:found)
|
||||
@config.find_and_execute_task("path:to:task", :after => :outgoing)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stack_inspector
|
||||
|
|
Loading…
Add table
Reference in a new issue