mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Added a dry-run option to see what commands will be run without actually running them
This commit is contained in:
parent
ad0a1c2c8b
commit
7279a3858e
7 changed files with 28 additions and 3 deletions
|
@ -23,6 +23,7 @@ module Capistrano
|
||||||
def execute!
|
def execute!
|
||||||
config = instantiate_configuration
|
config = instantiate_configuration
|
||||||
config.debug = options[:debug]
|
config.debug = options[:debug]
|
||||||
|
config.dry_run = options[:dry_run]
|
||||||
config.logger.level = options[:verbose]
|
config.logger.level = options[:verbose]
|
||||||
|
|
||||||
set_pre_vars(config)
|
set_pre_vars(config)
|
||||||
|
|
|
@ -31,6 +31,10 @@ module Capistrano
|
||||||
"Prompts before each remote command execution."
|
"Prompts before each remote command execution."
|
||||||
) { |value| options[:debug] = true }
|
) { |value| options[:debug] = true }
|
||||||
|
|
||||||
|
opts.on("-n", "--dry-run",
|
||||||
|
"Prints out commands without running them."
|
||||||
|
) { |value| options[:dry_run] = true }
|
||||||
|
|
||||||
opts.on("-e", "--explain TASK",
|
opts.on("-e", "--explain TASK",
|
||||||
"Displays help (if available) for the task."
|
"Displays help (if available) for the task."
|
||||||
) { |value| options[:explain] = value }
|
) { |value| options[:explain] = value }
|
||||||
|
|
|
@ -19,10 +19,11 @@ module Capistrano
|
||||||
# define roles, and set configuration variables.
|
# define roles, and set configuration variables.
|
||||||
class Configuration
|
class Configuration
|
||||||
# The logger instance defined for this configuration.
|
# The logger instance defined for this configuration.
|
||||||
attr_accessor :debug, :logger
|
attr_accessor :debug, :logger, :dry_run
|
||||||
|
|
||||||
def initialize #:nodoc:
|
def initialize #:nodoc:
|
||||||
@debug = false
|
@debug = false
|
||||||
|
@dry_run = false
|
||||||
@logger = Logger.new
|
@logger = Logger.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ module Capistrano
|
||||||
block ||= self.class.default_io_proc
|
block ||= self.class.default_io_proc
|
||||||
logger.debug "executing #{cmd.strip.inspect}"
|
logger.debug "executing #{cmd.strip.inspect}"
|
||||||
|
|
||||||
return if debug && continue_execution(cmd) == false
|
return if dry_run || (debug && continue_execution(cmd) == false)
|
||||||
|
|
||||||
options = add_default_command_options(options)
|
options = add_default_command_options(options)
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ class CLIExecuteTest < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@cli = MockCLI.new
|
@cli = MockCLI.new
|
||||||
@logger = stub_everything
|
@logger = stub_everything
|
||||||
@config = stub(:logger => @logger, :debug= => nil)
|
@config = stub(:logger => @logger, :debug= => nil, :dry_run= => nil)
|
||||||
@config.stubs(:set)
|
@config.stubs(:set)
|
||||||
@config.stubs(:load)
|
@config.stubs(:load)
|
||||||
@config.stubs(:trigger)
|
@config.stubs(:trigger)
|
||||||
|
|
|
@ -30,6 +30,18 @@ class CLIOptionsTest < Test::Unit::TestCase
|
||||||
assert @cli.options[:debug]
|
assert @cli.options[:debug]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_parse_options_with_n_should_set_dry_run_option
|
||||||
|
@cli.args << "-n"
|
||||||
|
@cli.parse_options!
|
||||||
|
assert @cli.options[:dry_run]
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_parse_options_with_dry_run_should_set_dry_run_option
|
||||||
|
@cli.args << "--dry-run"
|
||||||
|
@cli.parse_options!
|
||||||
|
assert @cli.options[:dry_run]
|
||||||
|
end
|
||||||
|
|
||||||
def test_parse_options_with_e_should_set_explain_option
|
def test_parse_options_with_e_should_set_explain_option
|
||||||
@cli.args << "-e" << "sample"
|
@cli.args << "-e" << "sample"
|
||||||
@cli.parse_options!
|
@cli.parse_options!
|
||||||
|
|
|
@ -5,6 +5,7 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
||||||
class MockConfig
|
class MockConfig
|
||||||
attr_reader :options
|
attr_reader :options
|
||||||
attr_accessor :debug
|
attr_accessor :debug
|
||||||
|
attr_accessor :dry_run
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@options = {}
|
@options = {}
|
||||||
|
@ -40,6 +41,12 @@ class ConfigurationActionsInvocationTest < Test::Unit::TestCase
|
||||||
@config.run "ls", :foo => "bar"
|
@config.run "ls", :foo => "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_run_will_return_if_dry_run
|
||||||
|
@config.expects(:dry_run).returns(true)
|
||||||
|
@config.expects(:execute_on_servers).never
|
||||||
|
@config.run "ls", :foo => "bar"
|
||||||
|
end
|
||||||
|
|
||||||
def test_run_without_block_should_use_default_io_proc
|
def test_run_without_block_should_use_default_io_proc
|
||||||
@config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| server(s) })
|
@config.expects(:execute_on_servers).yields(%w(s1 s2 s3).map { |s| server(s) })
|
||||||
@config.expects(:sessions).returns(Hash.new { |h,k| h[k] = k.host.to_sym }).times(3)
|
@config.expects(:sessions).returns(Hash.new { |h,k| h[k] = k.host.to_sym }).times(3)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue