mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
Merge pull request #1538 from gerardo-navarro/printing_config_variables
Enabling the printing of config variables with certain command line p…
This commit is contained in:
commit
dbe2b8b5c5
7 changed files with 56 additions and 1 deletions
|
@ -14,6 +14,7 @@ https://github.com/capistrano/capistrano/compare/v3.4.0...HEAD
|
|||
* Old versions of SSHKit (before 1.7.1) are no longer supported
|
||||
* Drop support for Ruby 1.9.3 (Capistrano may still work with 1.9.3, but it is
|
||||
no longer officially supported)
|
||||
* Added new runtime option `--print-config-variables` that inspect all defined config variables in order to assist development of new capistrano tasks (@gerardo-navarro)
|
||||
|
||||
* Minor changes
|
||||
* Fix filtering behaviour when using literal hostnames in on() block (@townsen)
|
||||
|
|
|
@ -162,6 +162,9 @@ $ bundle exec cap production deploy --prereqs
|
|||
|
||||
# trace through task invocations
|
||||
$ bundle exec cap production deploy --trace
|
||||
|
||||
# lists all config variable before deployment tasks
|
||||
$ bundle exec cap production deploy --print-config-variables
|
||||
```
|
||||
|
||||
## Finding help and documentation
|
||||
|
|
|
@ -21,7 +21,7 @@ module Capistrano
|
|||
switch =~ /--#{Regexp.union(not_applicable_to_capistrano)}/
|
||||
end
|
||||
|
||||
super.push(version, dry_run, roles, hostfilter)
|
||||
super.push(version, dry_run, roles, hostfilter, print_config_variables)
|
||||
end
|
||||
|
||||
def handle_options
|
||||
|
@ -140,6 +140,15 @@ module Capistrano
|
|||
]
|
||||
end
|
||||
|
||||
def print_config_variables
|
||||
['--print-config-variables', '-p',
|
||||
"Display the defined config variables before starting the deployment tasks.",
|
||||
lambda { |_value|
|
||||
Configuration.env.set(:print_config_variables, true)
|
||||
}
|
||||
]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -28,6 +28,10 @@ module Capistrano
|
|||
def set(key, value=nil, &block)
|
||||
invoke_validations(key, value, &block)
|
||||
config[key] = block || value
|
||||
|
||||
puts "Config variable set: #{key.inspect} => #{config[key].inspect}" if fetch(:print_config_variables, false)
|
||||
|
||||
config[key]
|
||||
end
|
||||
|
||||
def set_if_empty(key, value=nil, &block)
|
||||
|
@ -56,6 +60,11 @@ module Capistrano
|
|||
config.keys
|
||||
end
|
||||
|
||||
def is_question?(key)
|
||||
value = fetch_for(key, nil)
|
||||
not value.nil? and value.is_a?(Question)
|
||||
end
|
||||
|
||||
def role(name, hosts, options={})
|
||||
if name == :all
|
||||
raise ArgumentError.new("#{name} reserved name for role. Please choose another name")
|
||||
|
|
|
@ -8,6 +8,10 @@ module Capistrano
|
|||
:configure_backend, :fetch, :set, :set_if_empty, :delete,
|
||||
:ask, :role, :server, :primary, :validate
|
||||
|
||||
def is_question?(key)
|
||||
env.is_question?(key)
|
||||
end
|
||||
|
||||
def any?(key)
|
||||
value = fetch(key)
|
||||
if value && value.respond_to?(:any?)
|
||||
|
|
|
@ -1,10 +1,32 @@
|
|||
namespace :deploy do
|
||||
|
||||
task :starting do
|
||||
invoke 'deploy:print_config_variables' if fetch(:print_config_variables, false)
|
||||
invoke 'deploy:check'
|
||||
invoke 'deploy:set_previous_revision'
|
||||
end
|
||||
|
||||
task :print_config_variables do
|
||||
|
||||
puts
|
||||
puts '------- Printing current config variables -------'
|
||||
env.keys.each do |config_variable_key|
|
||||
if is_question?(config_variable_key)
|
||||
puts "#{config_variable_key.inspect} => Question (awaits user input on next fetch(#{config_variable_key.inspect}))"
|
||||
else
|
||||
puts "#{config_variable_key.inspect} => #{fetch(config_variable_key).inspect}"
|
||||
end
|
||||
end
|
||||
|
||||
puts
|
||||
puts '------- Printing current config variables of SSHKit mechanism -------'
|
||||
puts env.backend.config.inspect
|
||||
# puts env.backend.config.backend.config.ssh_options.inspect
|
||||
# puts env.backend.config.command_map.defaults.inspect
|
||||
|
||||
puts
|
||||
end
|
||||
|
||||
task :updating => :new_release_path do
|
||||
invoke "#{scm}:create_release"
|
||||
invoke "deploy:set_current_revision"
|
||||
|
|
|
@ -41,6 +41,13 @@ describe Capistrano::Application do
|
|||
expect(sshkit_backend).to eq(SSHKit::Backend::Printer)
|
||||
end
|
||||
|
||||
it 'enables printing all config variables on command line parameter' do
|
||||
capture_io do
|
||||
flags '--print-config-variables', '-p'
|
||||
end
|
||||
expect(Capistrano::Configuration.fetch(:print_config_variables)).to be true
|
||||
end
|
||||
|
||||
def flags(*sets)
|
||||
sets.each do |set|
|
||||
ARGV.clear
|
||||
|
|
Loading…
Add table
Reference in a new issue