mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Added $CAPISTRANO:HOST$ placeholder for commands
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6425 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
0e5600f1c9
commit
f8d425ef0d
3 changed files with 23 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Added $CAPISTRANO:HOST$ placeholder in commands, which will be replaced with the name of the host on which the command is executing [Jamis Buck]
|
||||
|
||||
* Added -e switch to explain specific task. Added -X to extend -x. Made -h much briefer. Added -T to list known tasks. [Jamis Buck]
|
||||
|
||||
* Added namespaces for tasks [Jamis Buck]
|
||||
|
|
|
@ -81,8 +81,8 @@ module Capistrano
|
|||
|
||||
channel.on_success do |ch|
|
||||
logger.trace "executing command", ch[:host] if logger
|
||||
ch.exec command
|
||||
ch.send_data options[:data] if options[:data]
|
||||
ch.exec(replace_placeholders(command, ch))
|
||||
ch.send_data(options[:data]) if options[:data]
|
||||
end
|
||||
|
||||
channel.on_failure do |ch|
|
||||
|
@ -112,6 +112,10 @@ module Capistrano
|
|||
end
|
||||
end
|
||||
|
||||
def replace_placeholders(command, channel)
|
||||
command.gsub(/\$CAPISTRANO:HOST\$/, channel[:host])
|
||||
end
|
||||
|
||||
# prepare a space-separated sequence of variables assignments
|
||||
# intended to be prepended to a command, so the shell sets
|
||||
# the environment before running the command.
|
||||
|
|
|
@ -214,6 +214,20 @@ class CommandTest < Test::Unit::TestCase
|
|||
assert_equal :command, parameter
|
||||
end
|
||||
|
||||
def test_process_with_host_placeholder_should_substitute_placeholder_with_each_host
|
||||
session = setup_for_extracting_channel_action(:on_success) do |ch|
|
||||
ch.expects(:exec).with("echo capistrano")
|
||||
end
|
||||
Capistrano::Command.new("echo $CAPISTRANO:HOST$", [session])
|
||||
end
|
||||
|
||||
def test_process_with_unknown_placeholder_should_not_replace_placeholder
|
||||
session = setup_for_extracting_channel_action(:on_success) do |ch|
|
||||
ch.expects(:exec).with("echo $CAPISTRANO:OTHER$")
|
||||
end
|
||||
Capistrano::Command.new("echo $CAPISTRANO:OTHER$", [session])
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def new_channel(closed, status=nil)
|
||||
|
@ -232,6 +246,7 @@ class CommandTest < Test::Unit::TestCase
|
|||
session.expects(:open_channel).yields(channel)
|
||||
|
||||
ch = mock
|
||||
ch.stubs(:[]).with(:host).returns("capistrano")
|
||||
channel.expects(action).yields(ch, *args)
|
||||
|
||||
yield ch if block_given?
|
||||
|
|
Loading…
Reference in a new issue