public
Description: Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Added a dry-run option to see what commands will be run without actually running 
them
pgr0ss (author)
Sat Jul 19 15:18:05 -0700 2008
commit  7279a3858e2bcebe84735223d5f8b4397c4ad85b
tree    acb1afe9bf0c12fbe29d72a52c47f1bac94f935f
parent  ad0a1c2c8bb4d481f59ce15267db1d9765f81554
...
23
24
25
 
26
27
28
...
23
24
25
26
27
28
29
0
@@ -23,6 +23,7 @@ module Capistrano
0
       def execute!
0
         config = instantiate_configuration
0
         config.debug = options[:debug]
0
+        config.dry_run = options[:dry_run]
0
         config.logger.level = options[:verbose]
0
 
0
         set_pre_vars(config)
...
31
32
33
 
 
 
 
34
35
36
...
31
32
33
34
35
36
37
38
39
40
0
@@ -31,6 +31,10 @@ module Capistrano
0
             "Prompts before each remote command execution."
0
           ) { |value| options[:debug] = true }
0
 
0
+          opts.on("-n", "--dry-run",
0
+            "Prints out commands without running them."
0
+          ) { |value| options[:dry_run] = true }
0
+
0
           opts.on("-e", "--explain TASK",
0
             "Displays help (if available) for the task."
0
           ) { |value| options[:explain] = value }
...
19
20
21
22
 
23
24
25
 
26
27
28
...
19
20
21
 
22
23
24
25
26
27
28
29
0
@@ -19,10 +19,11 @@ module Capistrano
0
   # define roles, and set configuration variables.
0
   class Configuration
0
     # The logger instance defined for this configuration.
0
-    attr_accessor :debug, :logger
0
+    attr_accessor :debug, :logger, :dry_run
0
 
0
     def initialize #:nodoc:
0
       @debug = false
0
+      @dry_run = false
0
       @logger = Logger.new
0
     end
0
 
...
46
47
48
49
 
50
51
52
...
46
47
48
 
49
50
51
52
0
@@ -46,7 +46,7 @@ module Capistrano
0
           block ||= self.class.default_io_proc
0
           logger.debug "executing #{cmd.strip.inspect}"
0
 
0
-          return if debug && continue_execution(cmd) == false
0
+          return if dry_run || (debug && continue_execution(cmd) == false)
0
 
0
           options = add_default_command_options(options)
0
 
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ class CLIExecuteTest < Test::Unit::TestCase
0
   def setup
0
     @cli = MockCLI.new
0
     @logger = stub_everything
0
-    @config = stub(:logger => @logger, :debug= => nil)
0
+    @config = stub(:logger => @logger, :debug= => nil, :dry_run= => nil)
0
     @config.stubs(:set)
0
     @config.stubs(:load)
0
     @config.stubs(:trigger)
...
30
31
32
 
 
 
 
 
 
 
 
 
 
 
 
33
34
35
...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
0
@@ -30,6 +30,18 @@ class CLIOptionsTest < Test::Unit::TestCase
0
     assert @cli.options[:debug]
0
   end
0
 
0
+  def test_parse_options_with_n_should_set_dry_run_option
0
+    @cli.args << "-n"
0
+    @cli.parse_options!
0
+    assert @cli.options[:dry_run]
0
+  end
0
+
0
+  def test_parse_options_with_dry_run_should_set_dry_run_option
0
+    @cli.args << "--dry-run"
0
+    @cli.parse_options!
0
+    assert @cli.options[:dry_run]
0
+  end
0
+
0
   def test_parse_options_with_e_should_set_explain_option
0
     @cli.args << "-e" << "sample"
0
     @cli.parse_options!
...
5
6
7
 
8
9
10
...
40
41
42
 
 
 
 
 
 
43
44
45
...
5
6
7
8
9
10
11
...
41
42
43
44
45
46
47
48
49
50
51
52
0
@@ -5,6 +5,7 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
0
   class MockConfig
0
     attr_reader :options
0
     attr_accessor :debug
0
+    attr_accessor :dry_run
0
 
0
     def initialize
0
       @options = {}
0
@@ -40,6 +41,12 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
0
     @config.run "ls", :foo => "bar"
0
   end
0
 
0
+  def test_run_will_return_if_dry_run
0
+    @config.expects(:dry_run).returns(true)
0
+    @config.expects(:execute_on_servers).never
0
+    @config.run "ls", :foo => "bar"
0
+  end
0
+
0
   def test_run_without_block_should_use_default_io_proc
0
     @config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| server(s) })
0
     @config.expects(:sessions).returns(Hash.new { |h,k| h[k] = k.host.to_sym }).times(3)

Comments