Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added $CAPISTRANO:HOST$ placeholder for commands

git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6425 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f8d425ef0d91d437ea9b5d80553c0cb1e76d680f 1 parent 0e5600f
@jamis jamis authored
Showing with 23 additions and 2 deletions.
  1. +2 −0  CHANGELOG
  2. +6 −2 lib/capistrano/command.rb
  3. +15 −0 test/command_test.rb
View
2  CHANGELOG
@@ -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]
View
8 lib/capistrano/command.rb
@@ -81,8 +81,8 @@ def open_channels
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 @@ def open_channels
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.
View
15 test/command_test.rb
@@ -214,6 +214,20 @@ def test_process_should_instantiate_command_and_process!
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 @@ def setup_for_extracting_channel_action(action, *args)
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?
Please sign in to comment.
Something went wrong with that request. Please try again.