capistrano 2.8.0 → 3.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.docker/Dockerfile +7 -0
- data/.docker/ssh_key_rsa +49 -0
- data/.docker/ssh_key_rsa.pub +1 -0
- data/.docker/ubuntu_setup.sh +23 -0
- data/.github/issue_template.md +19 -0
- data/.github/pull_request_template.md +22 -0
- data/.github/release-drafter.yml +25 -0
- data/.github/workflows/ci.yml +80 -0
- data/.github/workflows/release-drafter.yml +18 -0
- data/.gitignore +23 -8
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +1 -0
- data/CONTRIBUTING.md +63 -0
- data/DEVELOPMENT.md +112 -0
- data/Gemfile +42 -9
- data/LICENSE.txt +21 -0
- data/README.md +221 -0
- data/RELEASING.md +17 -0
- data/Rakefile +17 -8
- data/UPGRADING-3.7.md +86 -0
- data/bin/cap +2 -3
- data/bin/capify +7 -89
- data/capistrano.gemspec +29 -43
- data/docker-compose.yml +8 -0
- data/features/configuration.feature +28 -0
- data/features/deploy.feature +92 -0
- data/features/deploy_failure.feature +17 -0
- data/features/doctor.feature +11 -0
- data/features/installation.feature +21 -0
- data/features/sshconnect.feature +11 -0
- data/features/stage_failure.feature +9 -0
- data/features/step_definitions/assertions.rb +162 -0
- data/features/step_definitions/cap_commands.rb +21 -0
- data/features/step_definitions/setup.rb +91 -0
- data/features/subdirectory.feature +9 -0
- data/features/support/docker_gateway.rb +53 -0
- data/features/support/env.rb +1 -0
- data/features/support/remote_command_helpers.rb +29 -0
- data/features/support/remote_ssh_helpers.rb +33 -0
- data/lib/Capfile +3 -0
- data/lib/capistrano/all.rb +17 -0
- data/lib/capistrano/application.rb +153 -0
- data/lib/capistrano/configuration/empty_filter.rb +9 -0
- data/lib/capistrano/configuration/filter.rb +26 -0
- data/lib/capistrano/configuration/host_filter.rb +29 -0
- data/lib/capistrano/configuration/null_filter.rb +9 -0
- data/lib/capistrano/configuration/plugin_installer.rb +51 -0
- data/lib/capistrano/configuration/question.rb +76 -0
- data/lib/capistrano/configuration/role_filter.rb +29 -0
- data/lib/capistrano/configuration/scm_resolver.rb +149 -0
- data/lib/capistrano/configuration/server.rb +137 -0
- data/lib/capistrano/configuration/servers.rb +56 -96
- data/lib/capistrano/configuration/validated_variables.rb +110 -0
- data/lib/capistrano/configuration/variables.rb +79 -94
- data/lib/capistrano/configuration.rb +178 -33
- data/lib/capistrano/console.rb +1 -0
- data/lib/capistrano/defaults.rb +36 -0
- data/lib/capistrano/deploy.rb +3 -0
- data/lib/capistrano/doctor/environment_doctor.rb +19 -0
- data/lib/capistrano/doctor/gems_doctor.rb +45 -0
- data/lib/capistrano/doctor/output_helpers.rb +79 -0
- data/lib/capistrano/doctor/servers_doctor.rb +105 -0
- data/lib/capistrano/doctor/variables_doctor.rb +74 -0
- data/lib/capistrano/doctor.rb +6 -0
- data/lib/capistrano/dotfile.rb +2 -0
- data/lib/capistrano/dsl/env.rb +43 -0
- data/lib/capistrano/dsl/paths.rb +89 -0
- data/lib/capistrano/dsl/stages.rb +31 -0
- data/lib/capistrano/dsl/task_enhancements.rb +61 -0
- data/lib/capistrano/dsl.rb +95 -0
- data/lib/capistrano/framework.rb +2 -0
- data/lib/capistrano/i18n.rb +46 -0
- data/lib/capistrano/immutable_task.rb +30 -0
- data/lib/capistrano/install.rb +1 -0
- data/lib/capistrano/plugin.rb +95 -0
- data/lib/capistrano/proc_helpers.rb +13 -0
- data/lib/capistrano/scm/git.rb +105 -0
- data/lib/capistrano/scm/hg.rb +55 -0
- data/lib/capistrano/scm/plugin.rb +13 -0
- data/lib/capistrano/scm/svn.rb +56 -0
- data/lib/capistrano/scm/tasks/git.rake +84 -0
- data/lib/capistrano/scm/tasks/hg.rake +53 -0
- data/lib/capistrano/scm/tasks/svn.rake +53 -0
- data/lib/capistrano/scm.rb +115 -0
- data/lib/capistrano/setup.rb +36 -0
- data/lib/capistrano/tasks/console.rake +25 -0
- data/lib/capistrano/tasks/deploy.rake +280 -0
- data/lib/capistrano/tasks/doctor.rake +24 -0
- data/lib/capistrano/tasks/framework.rake +67 -0
- data/lib/capistrano/tasks/install.rake +41 -0
- data/lib/capistrano/templates/Capfile +38 -0
- data/lib/capistrano/templates/deploy.rb.erb +39 -0
- data/lib/capistrano/templates/stage.rb.erb +61 -0
- data/lib/capistrano/upload_task.rb +9 -0
- data/lib/capistrano/version.rb +1 -14
- data/lib/capistrano/version_validator.rb +32 -0
- data/lib/capistrano.rb +0 -3
- data/spec/integration/dsl_spec.rb +632 -0
- data/spec/integration_spec_helper.rb +5 -0
- data/spec/lib/capistrano/application_spec.rb +60 -0
- data/spec/lib/capistrano/configuration/empty_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/filter_spec.rb +109 -0
- data/spec/lib/capistrano/configuration/host_filter_spec.rb +71 -0
- data/spec/lib/capistrano/configuration/null_filter_spec.rb +17 -0
- data/spec/lib/capistrano/configuration/plugin_installer_spec.rb +98 -0
- data/spec/lib/capistrano/configuration/question_spec.rb +92 -0
- data/spec/lib/capistrano/configuration/role_filter_spec.rb +80 -0
- data/spec/lib/capistrano/configuration/scm_resolver_spec.rb +56 -0
- data/spec/lib/capistrano/configuration/server_spec.rb +309 -0
- data/spec/lib/capistrano/configuration/servers_spec.rb +331 -0
- data/spec/lib/capistrano/configuration_spec.rb +357 -0
- data/spec/lib/capistrano/doctor/environment_doctor_spec.rb +44 -0
- data/spec/lib/capistrano/doctor/gems_doctor_spec.rb +67 -0
- data/spec/lib/capistrano/doctor/output_helpers_spec.rb +47 -0
- data/spec/lib/capistrano/doctor/servers_doctor_spec.rb +86 -0
- data/spec/lib/capistrano/doctor/variables_doctor_spec.rb +89 -0
- data/spec/lib/capistrano/dsl/paths_spec.rb +228 -0
- data/spec/lib/capistrano/dsl/task_enhancements_spec.rb +108 -0
- data/spec/lib/capistrano/dsl_spec.rb +125 -0
- data/spec/lib/capistrano/immutable_task_spec.rb +31 -0
- data/spec/lib/capistrano/plugin_spec.rb +84 -0
- data/spec/lib/capistrano/scm/git_spec.rb +194 -0
- data/spec/lib/capistrano/scm/hg_spec.rb +109 -0
- data/spec/lib/capistrano/scm/svn_spec.rb +137 -0
- data/spec/lib/capistrano/scm_spec.rb +103 -0
- data/spec/lib/capistrano/upload_task_spec.rb +19 -0
- data/spec/lib/capistrano/version_validator_spec.rb +118 -0
- data/spec/lib/capistrano_spec.rb +7 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/matchers.rb +5 -0
- data/spec/support/tasks/database.rake +11 -0
- data/spec/support/tasks/fail.rake +8 -0
- data/spec/support/tasks/failed.rake +5 -0
- data/spec/support/tasks/plugin.rake +6 -0
- data/spec/support/tasks/root.rake +11 -0
- data/spec/support/test_app.rb +205 -0
- metadata +234 -208
- data/.rvmrc +0 -1
- data/CHANGELOG +0 -954
- data/README.mdown +0 -76
- data/lib/capistrano/callback.rb +0 -45
- data/lib/capistrano/cli/execute.rb +0 -85
- data/lib/capistrano/cli/help.rb +0 -125
- data/lib/capistrano/cli/help.txt +0 -81
- data/lib/capistrano/cli/options.rb +0 -243
- data/lib/capistrano/cli/ui.rb +0 -40
- data/lib/capistrano/cli.rb +0 -47
- data/lib/capistrano/command.rb +0 -286
- data/lib/capistrano/configuration/actions/file_transfer.rb +0 -51
- data/lib/capistrano/configuration/actions/inspect.rb +0 -46
- data/lib/capistrano/configuration/actions/invocation.rb +0 -298
- data/lib/capistrano/configuration/callbacks.rb +0 -148
- data/lib/capistrano/configuration/connections.rb +0 -230
- data/lib/capistrano/configuration/execution.rb +0 -143
- data/lib/capistrano/configuration/loading.rb +0 -197
- data/lib/capistrano/configuration/namespaces.rb +0 -197
- data/lib/capistrano/configuration/roles.rb +0 -73
- data/lib/capistrano/errors.rb +0 -19
- data/lib/capistrano/ext/string.rb +0 -5
- data/lib/capistrano/extensions.rb +0 -57
- data/lib/capistrano/logger.rb +0 -59
- data/lib/capistrano/processable.rb +0 -53
- data/lib/capistrano/recipes/compat.rb +0 -32
- data/lib/capistrano/recipes/deploy/assets.rb +0 -57
- data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
- data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
- data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -111
- data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
- data/lib/capistrano/recipes/deploy/scm/base.rb +0 -196
- data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
- data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
- data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
- data/lib/capistrano/recipes/deploy/scm/git.rb +0 -282
- data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
- data/lib/capistrano/recipes/deploy/scm/none.rb +0 -44
- data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -138
- data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
- data/lib/capistrano/recipes/deploy/scm.rb +0 -19
- data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -88
- data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -224
- data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
- data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
- data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
- data/lib/capistrano/recipes/deploy/strategy.rb +0 -19
- data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/recipes/deploy.rb +0 -568
- data/lib/capistrano/recipes/standard.rb +0 -37
- data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
- data/lib/capistrano/role.rb +0 -102
- data/lib/capistrano/server_definition.rb +0 -56
- data/lib/capistrano/shell.rb +0 -260
- data/lib/capistrano/ssh.rb +0 -101
- data/lib/capistrano/task_definition.rb +0 -75
- data/lib/capistrano/transfer.rb +0 -216
- data/rvmrc.sample +0 -1
- data/test/cli/execute_test.rb +0 -132
- data/test/cli/help_test.rb +0 -165
- data/test/cli/options_test.rb +0 -329
- data/test/cli/ui_test.rb +0 -28
- data/test/cli_test.rb +0 -17
- data/test/command_test.rb +0 -289
- data/test/configuration/actions/file_transfer_test.rb +0 -61
- data/test/configuration/actions/inspect_test.rb +0 -65
- data/test/configuration/actions/invocation_test.rb +0 -247
- data/test/configuration/callbacks_test.rb +0 -220
- data/test/configuration/connections_test.rb +0 -420
- data/test/configuration/execution_test.rb +0 -175
- data/test/configuration/loading_test.rb +0 -132
- data/test/configuration/namespace_dsl_test.rb +0 -311
- data/test/configuration/roles_test.rb +0 -144
- data/test/configuration/servers_test.rb +0 -183
- data/test/configuration/variables_test.rb +0 -190
- data/test/configuration_test.rb +0 -88
- data/test/deploy/local_dependency_test.rb +0 -76
- data/test/deploy/remote_dependency_test.rb +0 -135
- data/test/deploy/scm/accurev_test.rb +0 -23
- data/test/deploy/scm/base_test.rb +0 -55
- data/test/deploy/scm/bzr_test.rb +0 -51
- data/test/deploy/scm/darcs_test.rb +0 -37
- data/test/deploy/scm/git_test.rb +0 -184
- data/test/deploy/scm/mercurial_test.rb +0 -134
- data/test/deploy/scm/none_test.rb +0 -35
- data/test/deploy/scm/subversion_test.rb +0 -32
- data/test/deploy/strategy/copy_test.rb +0 -321
- data/test/extensions_test.rb +0 -69
- data/test/fixtures/cli_integration.rb +0 -5
- data/test/fixtures/config.rb +0 -5
- data/test/fixtures/custom.rb +0 -3
- data/test/logger_test.rb +0 -123
- data/test/recipes_test.rb +0 -25
- data/test/role_test.rb +0 -11
- data/test/server_definition_test.rb +0 -121
- data/test/shell_test.rb +0 -90
- data/test/ssh_test.rb +0 -113
- data/test/task_definition_test.rb +0 -116
- data/test/transfer_test.rb +0 -160
- data/test/utils.rb +0 -37
data/README.mdown
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
## Capistrano
|
2
|
-
|
3
|
-
Capistrano is a utility and framework for executing commands in parallel on
|
4
|
-
multiple remote machines, via SSH. It uses a simple DSL (borrowed in part from
|
5
|
-
[Rake](http://rake.rubyforge.org/)) that allows you to define _tasks_, which may
|
6
|
-
be applied to machines in certain roles. It also supports tunneling connections
|
7
|
-
via some gateway machine to allow operations to be performed behind VPN's and
|
8
|
-
firewalls.
|
9
|
-
|
10
|
-
Capistrano was originally designed to simplify and automate deployment of web
|
11
|
-
applications to distributed environments, and originally came bundled with a set
|
12
|
-
of tasks designed for deploying Rails applications.
|
13
|
-
|
14
|
-
## Documentation
|
15
|
-
|
16
|
-
* [http://github.com/capistrano/capistrano/wiki/Documentation-v2.x](http://github.com/capistrano/capistrano/wiki/Documentation-v2.x)
|
17
|
-
|
18
|
-
## DEPENDENCIES
|
19
|
-
|
20
|
-
* [Net::SSH](http://net-ssh.rubyforge.org)
|
21
|
-
* [Net::SFTP](http://net-ssh.rubyforge.org)
|
22
|
-
* [Net::SCP](http://net-ssh.rubyforge.org)
|
23
|
-
* [Net::SSH::Gateway](http://net-ssh.rubyforge.org)
|
24
|
-
* [HighLine](http://highline.rubyforge.org)
|
25
|
-
|
26
|
-
If you want to run the tests, you'll also need to install the dependencies with
|
27
|
-
Bundler, see the `Gemfile` within .
|
28
|
-
|
29
|
-
## ASSUMPTIONS
|
30
|
-
|
31
|
-
Capistrano is "opinionated software", which means it has very firm ideas about
|
32
|
-
how things ought to be done, and tries to force those ideas on you. Some of the
|
33
|
-
assumptions behind these opinions are:
|
34
|
-
|
35
|
-
* You are using SSH to access the remote servers.
|
36
|
-
* You either have the same password to all target machines, or you have public
|
37
|
-
keys in place to allow passwordless access to them.
|
38
|
-
|
39
|
-
Do not expect these assumptions to change.
|
40
|
-
|
41
|
-
## USAGE
|
42
|
-
|
43
|
-
In general, you'll use Capistrano as follows:
|
44
|
-
|
45
|
-
* Create a recipe file ("capfile" or "Capfile").
|
46
|
-
* Use the `cap` script to execute your recipe.
|
47
|
-
|
48
|
-
Use the `cap` script as follows:
|
49
|
-
|
50
|
-
cap sometask
|
51
|
-
|
52
|
-
By default, the script will look for a file called one of `capfile` or
|
53
|
-
`Capfile`. The `someaction` text indicates which task to execute. You can do
|
54
|
-
"cap -h" to see all the available options and "cap -T" to see all the available
|
55
|
-
tasks.
|
56
|
-
|
57
|
-
## LICENSE:
|
58
|
-
|
59
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
60
|
-
a copy of this software and associated documentation files (the
|
61
|
-
'Software'), to deal in the Software without restriction, including
|
62
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
63
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
64
|
-
permit persons to whom the Software is furnished to do so, subject to
|
65
|
-
the following conditions:
|
66
|
-
|
67
|
-
The above copyright notice and this permission notice shall be
|
68
|
-
included in all copies or substantial portions of the Software.
|
69
|
-
|
70
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
71
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
72
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
73
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
74
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
75
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
76
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/capistrano/callback.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
module Capistrano
|
2
|
-
class Callback
|
3
|
-
attr_reader :source, :options, :only, :except
|
4
|
-
|
5
|
-
def initialize(source, options={})
|
6
|
-
@source = source
|
7
|
-
@options = options
|
8
|
-
@only = Array(options[:only]).map { |v| v.to_s }
|
9
|
-
@except = Array(options[:except]).map { |v| v.to_s }
|
10
|
-
end
|
11
|
-
|
12
|
-
def applies_to?(task)
|
13
|
-
if task && only.any?
|
14
|
-
return only.include?(task.fully_qualified_name)
|
15
|
-
elsif task && except.any?
|
16
|
-
return !except.include?(task.fully_qualified_name)
|
17
|
-
else
|
18
|
-
return true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class ProcCallback < Callback
|
24
|
-
def call
|
25
|
-
source.call
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class TaskCallback < Callback
|
30
|
-
attr_reader :config
|
31
|
-
|
32
|
-
def initialize(config, source, options={})
|
33
|
-
super(source, options)
|
34
|
-
@config = config
|
35
|
-
end
|
36
|
-
|
37
|
-
def call
|
38
|
-
config.find_and_execute_task(source)
|
39
|
-
end
|
40
|
-
|
41
|
-
def applies_to?(task)
|
42
|
-
super && (task.nil? || task.fully_qualified_name != source.to_s)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'capistrano/configuration'
|
2
|
-
|
3
|
-
module Capistrano
|
4
|
-
class CLI
|
5
|
-
module Execute
|
6
|
-
def self.included(base) #:nodoc:
|
7
|
-
base.extend(ClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
# Invoke capistrano using the ARGV array as the option parameters. This
|
12
|
-
# is what the command-line capistrano utility does.
|
13
|
-
def execute
|
14
|
-
parse(ARGV).execute!
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
# Using the options build when the command-line was parsed, instantiate
|
19
|
-
# a new Capistrano configuration, initialize it, and execute the
|
20
|
-
# requested actions.
|
21
|
-
#
|
22
|
-
# Returns the Configuration instance used, if successful.
|
23
|
-
def execute!
|
24
|
-
config = instantiate_configuration(options)
|
25
|
-
config.debug = options[:debug]
|
26
|
-
config.dry_run = options[:dry_run]
|
27
|
-
config.preserve_roles = options[:preserve_roles]
|
28
|
-
config.logger.level = options[:verbose]
|
29
|
-
|
30
|
-
set_pre_vars(config)
|
31
|
-
load_recipes(config)
|
32
|
-
|
33
|
-
config.trigger(:load)
|
34
|
-
execute_requested_actions(config)
|
35
|
-
config.trigger(:exit)
|
36
|
-
|
37
|
-
config
|
38
|
-
rescue Exception => error
|
39
|
-
handle_error(error)
|
40
|
-
end
|
41
|
-
|
42
|
-
def execute_requested_actions(config)
|
43
|
-
Array(options[:vars]).each { |name, value| config.set(name, value) }
|
44
|
-
|
45
|
-
Array(options[:actions]).each do |action|
|
46
|
-
config.find_and_execute_task(action, :before => :start, :after => :finish)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_pre_vars(config) #:nodoc:
|
51
|
-
config.set :password, options[:password]
|
52
|
-
Array(options[:pre_vars]).each { |name, value| config.set(name, value) }
|
53
|
-
end
|
54
|
-
|
55
|
-
def load_recipes(config) #:nodoc:
|
56
|
-
# load the standard recipe definition
|
57
|
-
config.load "standard"
|
58
|
-
|
59
|
-
# load systemwide config/recipe definition
|
60
|
-
config.load(options[:sysconf]) if options[:sysconf] && File.file?(options[:sysconf])
|
61
|
-
|
62
|
-
# load user config/recipe definition
|
63
|
-
config.load(options[:dotfile]) if options[:dotfile] && File.file?(options[:dotfile])
|
64
|
-
|
65
|
-
Array(options[:recipes]).each { |recipe| config.load(recipe) }
|
66
|
-
end
|
67
|
-
|
68
|
-
# Primarily useful for testing, but subclasses of CLI could conceivably
|
69
|
-
# override this method to return a Configuration subclass or replacement.
|
70
|
-
def instantiate_configuration(options={}) #:nodoc:
|
71
|
-
Capistrano::Configuration.new(options)
|
72
|
-
end
|
73
|
-
|
74
|
-
def handle_error(error) #:nodoc:
|
75
|
-
case error
|
76
|
-
when Net::SSH::AuthenticationFailed
|
77
|
-
abort "authentication failed for `#{error.message}'"
|
78
|
-
when Capistrano::Error
|
79
|
-
abort(error.message)
|
80
|
-
else raise error
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
data/lib/capistrano/cli/help.rb
DELETED
@@ -1,125 +0,0 @@
|
|
1
|
-
module Capistrano
|
2
|
-
class CLI
|
3
|
-
module Help
|
4
|
-
LINE_PADDING = 7
|
5
|
-
MIN_MAX_LEN = 30
|
6
|
-
HEADER_LEN = 60
|
7
|
-
|
8
|
-
def self.included(base) #:nodoc:
|
9
|
-
base.send :alias_method, :execute_requested_actions_without_help, :execute_requested_actions
|
10
|
-
base.send :alias_method, :execute_requested_actions, :execute_requested_actions_with_help
|
11
|
-
end
|
12
|
-
|
13
|
-
def execute_requested_actions_with_help(config)
|
14
|
-
if options[:tasks]
|
15
|
-
task_list(config, options[:tasks])
|
16
|
-
elsif options[:explain]
|
17
|
-
explain_task(config, options[:explain])
|
18
|
-
else
|
19
|
-
execute_requested_actions_without_help(config)
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def task_list(config, pattern = true) #:nodoc:
|
24
|
-
tool_output = options[:tool]
|
25
|
-
|
26
|
-
if pattern.is_a?(String)
|
27
|
-
tasks = config.task_list(:all).select {|t| t.fully_qualified_name =~ /#{pattern}/}
|
28
|
-
end
|
29
|
-
if tasks.nil? || tasks.length == 0
|
30
|
-
warn "Pattern '#{pattern}' not found. Listing all tasks.\n\n" if !tool_output && !pattern.is_a?(TrueClass)
|
31
|
-
tasks = config.task_list(:all)
|
32
|
-
end
|
33
|
-
|
34
|
-
if tasks.empty?
|
35
|
-
warn "There are no tasks available. Please specify a recipe file to load." unless tool_output
|
36
|
-
else
|
37
|
-
all_tasks_length = tasks.length
|
38
|
-
if options[:verbose].to_i < 1
|
39
|
-
tasks = tasks.reject { |t| t.description.empty? || t.description =~ /^\[internal\]/ }
|
40
|
-
end
|
41
|
-
|
42
|
-
tasks = tasks.sort_by { |task| task.fully_qualified_name }
|
43
|
-
|
44
|
-
longest = tasks.map { |task| task.fully_qualified_name.length }.max
|
45
|
-
max_length = output_columns - longest - LINE_PADDING
|
46
|
-
max_length = MIN_MAX_LEN if max_length < MIN_MAX_LEN
|
47
|
-
|
48
|
-
tasks.each do |task|
|
49
|
-
if tool_output
|
50
|
-
puts "cap #{task.fully_qualified_name}"
|
51
|
-
else
|
52
|
-
puts "cap %-#{longest}s # %s" % [task.fully_qualified_name, task.brief_description(max_length)]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
unless tool_output
|
57
|
-
if all_tasks_length > tasks.length
|
58
|
-
puts
|
59
|
-
puts "Some tasks were not listed, either because they have no description,"
|
60
|
-
puts "or because they are only used internally by other tasks. To see all"
|
61
|
-
puts "tasks, type `#{File.basename($0)} -vT'."
|
62
|
-
end
|
63
|
-
|
64
|
-
puts
|
65
|
-
puts "Extended help may be available for these tasks."
|
66
|
-
puts "Type `#{File.basename($0)} -e taskname' to view it."
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def explain_task(config, name) #:nodoc:
|
72
|
-
task = config.find_task(name)
|
73
|
-
if task.nil?
|
74
|
-
warn "The task `#{name}' does not exist."
|
75
|
-
else
|
76
|
-
puts "-" * HEADER_LEN
|
77
|
-
puts "cap #{name}"
|
78
|
-
puts "-" * HEADER_LEN
|
79
|
-
|
80
|
-
if task.description.empty?
|
81
|
-
puts "There is no description for this task."
|
82
|
-
else
|
83
|
-
puts format_text(task.description)
|
84
|
-
end
|
85
|
-
|
86
|
-
puts
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
def long_help #:nodoc:
|
91
|
-
help_text = File.read(File.join(File.dirname(__FILE__), "help.txt"))
|
92
|
-
self.class.ui.page_at = self.class.ui.output_rows - 2
|
93
|
-
self.class.ui.say format_text(help_text)
|
94
|
-
end
|
95
|
-
|
96
|
-
def format_text(text) #:nodoc:
|
97
|
-
formatted = ""
|
98
|
-
text.each_line do |line|
|
99
|
-
indentation = line[/^\s+/] || ""
|
100
|
-
indentation_size = indentation.split(//).inject(0) { |c,s| c + (s[0] == ?\t ? 8 : 1) }
|
101
|
-
line_length = output_columns - indentation_size
|
102
|
-
line_length = MIN_MAX_LEN if line_length < MIN_MAX_LEN
|
103
|
-
lines = line.strip.gsub(/(.{1,#{line_length}})(?:\s+|\Z)/, "\\1\n").split(/\n/)
|
104
|
-
if lines.empty?
|
105
|
-
formatted << "\n"
|
106
|
-
else
|
107
|
-
formatted << lines.map { |l| "#{indentation}#{l}\n" }.join
|
108
|
-
end
|
109
|
-
end
|
110
|
-
formatted
|
111
|
-
end
|
112
|
-
|
113
|
-
def output_columns #:nodoc:
|
114
|
-
if ( @output_columns.nil? )
|
115
|
-
if ( self.class.ui.output_cols.nil? || self.class.ui.output_cols > 80 )
|
116
|
-
@output_columns = 80
|
117
|
-
else
|
118
|
-
@output_columns = self.class.ui.output_cols
|
119
|
-
end
|
120
|
-
end
|
121
|
-
@output_columns
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
data/lib/capistrano/cli/help.txt
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
-----------------------------
|
2
|
-
<%= color('Capistrano', :bold) %>
|
3
|
-
-----------------------------
|
4
|
-
|
5
|
-
Capistrano is a utility for automating the execution of commands across multiple remote machines. It was originally conceived as an aid to deploy Ruby on Rails web applications, but has since evolved to become a much more general-purpose tool.
|
6
|
-
|
7
|
-
The command-line interface to Capistrano is via the `cap' command.
|
8
|
-
|
9
|
-
cap [ option ] ... action ...
|
10
|
-
|
11
|
-
The following options are understood:
|
12
|
-
|
13
|
-
<%= color '-d, --debug', :bold %>
|
14
|
-
Causes Capistrano to pause and prompt before executing any remote command, giving the user the option to either execute the command, skip the command, or abort execution entirely. This makes it a great way to troubleshoot tasks, or test custom tasks, by executing commands one at a time and checking the server to make sure they worked as expected before moving on to the next command. (Compare this to the --dry-run command.)
|
15
|
-
|
16
|
-
<%= color '-e, --explain TASK', :bold %>
|
17
|
-
Displays the extended description of the given task. Not all tasks will have an extended description, but for those that do, this can provide a wealth of additional usage information, such as describing environment variables or settings that can affect the execution of the task.
|
18
|
-
|
19
|
-
<%= color '-F, --default-config', :bold %>
|
20
|
-
By default, cap will search for a config file named `Capfile' or `capfile' in the current directory, or in any parent directory, and will automatically load it. However, if you specify the -f flag (see below), cap will use that file instead of the default config. If you want to use both the default config, and files loaded via -f, you can specify -F to force cap to search for and load the default config, even if additional files were specified via -f.
|
21
|
-
|
22
|
-
<%= color '-f, --file FILE', :bold %>
|
23
|
-
Causes the named file to be loaded. Capistrano will search both its own recipe directory, as well as the current directory, looking for the named file. An ".rb" extension is optional. The -f option may be given any number of times, but if it is given, it will take the place of the normal `Capfile' or `capfile' detection. Use -F if you want the default capfile to be loaded when you use -f.
|
24
|
-
|
25
|
-
<%= color '-H, --long-help', :bold %>
|
26
|
-
Displays this document and exits.
|
27
|
-
|
28
|
-
<%= color '-h, --help', :bold %>
|
29
|
-
Shows a brief summary of these options and exits.
|
30
|
-
|
31
|
-
<%= color '-l, --logger [STDERR|STDOUT|file]', :bold %>
|
32
|
-
Change the file used to print the output. It offers three options: standard error(stderr), standard output and file. Options are not case sensitive. By default Capistrano uses stderr.
|
33
|
-
|
34
|
-
<%= color '-n, --dry-run', :bold %>
|
35
|
-
Causes Capistrano to simply display each remote command, without executing it. In this sense it is similar to --debug, but without the prompt. Note that commands executed locally are still run--only remote commands are skipped.
|
36
|
-
|
37
|
-
<%= color '-p, --password', :bold %>
|
38
|
-
Normally, cap will prompt for the password on-demand, the first time it is needed. This can make it hard to walk away from Capistrano, since you might not know if it will prompt for a password down the road. In such cases, you can use the -p option to force cap to prompt for the password immediately.
|
39
|
-
|
40
|
-
<%= color '-q, --quiet', :bold %>
|
41
|
-
Display only critical error messages. All other output is suppressed.
|
42
|
-
|
43
|
-
<%= color '-S, --set-before NAME=VALUE', :bold %>
|
44
|
-
Sets the given variable to the given value, before loading any recipe files. This is useful if you have a recipe file that depends on a certain variable being set, at the time it is loaded.
|
45
|
-
|
46
|
-
<%= color '-s, --set NAME=VALUE', :bold %>
|
47
|
-
Sets the given variable to the given value, after loading all recipe files. This is useful when you want to override the value of a variable which is used in a task. Note that this will set the variables too late for them to affect conditions that are executed as the recipes are loaded.
|
48
|
-
|
49
|
-
<%= color '-T, --tasks PATTERN', :bold %>
|
50
|
-
Displays the list of all tasks (matching optional PATTERN) in all loaded recipe files. If a task has no description, or if the description starts with the [internal] tag, the task will not be listed unless you also specify -v.
|
51
|
-
|
52
|
-
<%= color '-t, --tool', :bold %>
|
53
|
-
Abbreviates the output of -T for integration with other tools. Without -t, -T will list tasks with their summaries, and may include additional instructive text at the bottom. When integrating with other tools (e.g., bash auto-expansion and the like) that additional text can get in the way. This switch makes it easier for those tools to parse the list of tasks. (The -t switch has no effect if the -T switch is not specified.)
|
54
|
-
|
55
|
-
<%= color '-V, --version', :bold %>
|
56
|
-
Shows the current Capistrano version number and exits.
|
57
|
-
|
58
|
-
<%= color '-v, --verbose', :bold %>
|
59
|
-
Increase the verbosity. You can specify this option up to three times to further increase verbosity. By default, cap will use maximum verbosity, but if you specify an explicit verbosity, that will be used instead. See also -q.
|
60
|
-
|
61
|
-
<%= color '-X, --skip-system-config', :bold %>
|
62
|
-
By default, cap will look for and (if it exists) load the global system configuration file located in /etc/capistrano.conf. If you don't want cap to load that file, give this option.
|
63
|
-
|
64
|
-
<%= color '-x, --skip-user-config', :bold %>
|
65
|
-
By default, cap will look for and (if it exists) load the user-specific configuration file located in $HOME/.caprc. If you don't want cap to load that file, give this option.
|
66
|
-
|
67
|
-
-----------------------------
|
68
|
-
<%= color('Environment Variables', :bold) %>
|
69
|
-
-----------------------------
|
70
|
-
|
71
|
-
<%= color 'HOSTS', :bold %>
|
72
|
-
Execute the tasks against this comma-separated list of hosts. Effectively, this makes the host(s) part of every roles.
|
73
|
-
|
74
|
-
<%= color 'HOSTFILTER', :bold %>
|
75
|
-
Execute tasks against this comma-separated list of host, but only if the host has the proper role for the task.
|
76
|
-
|
77
|
-
<%= color 'HOSTROLEFILTER', :bold %>
|
78
|
-
Execute tasks against the hosts in this comma-separated list of roles, but only if the host has the proper role for the task.
|
79
|
-
|
80
|
-
<%= color 'ROLES', :bold %>
|
81
|
-
Execute tasks against this comma-separated list of roles. Hosts which do not have the right roles will be skipped.
|
@@ -1,243 +0,0 @@
|
|
1
|
-
require 'optparse'
|
2
|
-
|
3
|
-
module Capistrano
|
4
|
-
class CLI
|
5
|
-
module Options
|
6
|
-
def self.included(base)
|
7
|
-
base.extend(ClassMethods)
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
# Return a new CLI instance with the given arguments pre-parsed and
|
12
|
-
# ready for execution.
|
13
|
-
def parse(args)
|
14
|
-
cli = new(args)
|
15
|
-
cli.parse_options!
|
16
|
-
cli
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# The hash of (parsed) command-line options
|
21
|
-
attr_reader :options
|
22
|
-
|
23
|
-
# Return an OptionParser instance that defines the acceptable command
|
24
|
-
# line switches for Capistrano, and what their corresponding behaviors
|
25
|
-
# are.
|
26
|
-
def option_parser #:nodoc:
|
27
|
-
@logger = Logger.new
|
28
|
-
@option_parser ||= OptionParser.new do |opts|
|
29
|
-
opts.banner = "Usage: #{File.basename($0)} [options] action ..."
|
30
|
-
|
31
|
-
opts.on("-d", "--debug",
|
32
|
-
"Prompts before each remote command execution."
|
33
|
-
) { |value| options[:debug] = true }
|
34
|
-
|
35
|
-
opts.on("-e", "--explain TASK",
|
36
|
-
"Displays help (if available) for the task."
|
37
|
-
) { |value| options[:explain] = value }
|
38
|
-
|
39
|
-
opts.on("-F", "--default-config",
|
40
|
-
"Always use default config, even with -f."
|
41
|
-
) { options[:default_config] = true }
|
42
|
-
|
43
|
-
opts.on("-f", "--file FILE",
|
44
|
-
"A recipe file to load. May be given more than once."
|
45
|
-
) { |value| options[:recipes] << value }
|
46
|
-
|
47
|
-
opts.on("-H", "--long-help", "Explain these options and environment variables.") do
|
48
|
-
long_help
|
49
|
-
exit
|
50
|
-
end
|
51
|
-
|
52
|
-
opts.on("-h", "--help", "Display this help message.") do
|
53
|
-
puts opts
|
54
|
-
exit
|
55
|
-
end
|
56
|
-
|
57
|
-
opts.on("-l", "--logger [STDERR|STDOUT|file]",
|
58
|
-
"Choose logger method. STDERR used by default."
|
59
|
-
) do |value|
|
60
|
-
options[:output] = if value.nil? || value.upcase == 'STDERR'
|
61
|
-
# Using default logger.
|
62
|
-
nil
|
63
|
-
elsif value.upcase == 'STDOUT'
|
64
|
-
$stdout
|
65
|
-
else
|
66
|
-
value
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
opts.on("-n", "--dry-run",
|
71
|
-
"Prints out commands without running them."
|
72
|
-
) { |value| options[:dry_run] = true }
|
73
|
-
|
74
|
-
opts.on("-p", "--password",
|
75
|
-
"Immediately prompt for the password."
|
76
|
-
) { options[:password] = nil }
|
77
|
-
|
78
|
-
opts.on("-q", "--quiet",
|
79
|
-
"Make the output as quiet as possible."
|
80
|
-
) { options[:verbose] = 0 }
|
81
|
-
|
82
|
-
opts.on("-r", "--preserve-roles",
|
83
|
-
"Preserve task roles"
|
84
|
-
) { options[:preserve_roles] = true }
|
85
|
-
|
86
|
-
opts.on("-S", "--set-before NAME=VALUE",
|
87
|
-
"Set a variable before the recipes are loaded."
|
88
|
-
) do |pair|
|
89
|
-
name, value = pair.split(/=/, 2)
|
90
|
-
options[:pre_vars][name.to_sym] = value
|
91
|
-
end
|
92
|
-
|
93
|
-
opts.on("-s", "--set NAME=VALUE",
|
94
|
-
"Set a variable after the recipes are loaded."
|
95
|
-
) do |pair|
|
96
|
-
name, value = pair.split(/=/, 2)
|
97
|
-
options[:vars][name.to_sym] = value
|
98
|
-
end
|
99
|
-
|
100
|
-
opts.on("-T", "--tasks [PATTERN]",
|
101
|
-
"List all tasks (matching optional PATTERN) in the loaded recipe files."
|
102
|
-
) do |value|
|
103
|
-
options[:tasks] = if value
|
104
|
-
value
|
105
|
-
else
|
106
|
-
true
|
107
|
-
end
|
108
|
-
options[:verbose] ||= 0
|
109
|
-
end
|
110
|
-
|
111
|
-
opts.on("-t", "--tool",
|
112
|
-
"Abbreviates the output of -T for tool integration."
|
113
|
-
) { options[:tool] = true }
|
114
|
-
|
115
|
-
opts.on("-V", "--version",
|
116
|
-
"Display the Capistrano version, and exit."
|
117
|
-
) do
|
118
|
-
require 'capistrano/version'
|
119
|
-
puts "Capistrano v#{Capistrano::Version}"
|
120
|
-
exit
|
121
|
-
end
|
122
|
-
|
123
|
-
opts.on("-v", "--verbose",
|
124
|
-
"Be more verbose. May be given more than once."
|
125
|
-
) do
|
126
|
-
options[:verbose] ||= 0
|
127
|
-
options[:verbose] += 1
|
128
|
-
end
|
129
|
-
|
130
|
-
opts.on("-X", "--skip-system-config",
|
131
|
-
"Don't load the system config file (capistrano.conf)"
|
132
|
-
) { options.delete(:sysconf) }
|
133
|
-
|
134
|
-
opts.on("-x", "--skip-user-config",
|
135
|
-
"Don't load the user config file (.caprc)"
|
136
|
-
) { options.delete(:dotfile) }
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
# If the arguments to the command are empty, this will print the
|
141
|
-
# allowed options and exit. Otherwise, it will parse the command
|
142
|
-
# line and set up any default options.
|
143
|
-
def parse_options! #:nodoc:
|
144
|
-
@options = { :recipes => [], :actions => [],
|
145
|
-
:vars => {}, :pre_vars => {},
|
146
|
-
:sysconf => default_sysconf, :dotfile => default_dotfile }
|
147
|
-
|
148
|
-
if args.empty?
|
149
|
-
warn "Please specify at least one action to execute."
|
150
|
-
warn option_parser
|
151
|
-
exit
|
152
|
-
end
|
153
|
-
|
154
|
-
option_parser.parse!(args)
|
155
|
-
|
156
|
-
coerce_variable_types!
|
157
|
-
|
158
|
-
# if no verbosity has been specified, be verbose
|
159
|
-
options[:verbose] = 3 if !options.has_key?(:verbose)
|
160
|
-
|
161
|
-
look_for_default_recipe_file! if options[:default_config] || options[:recipes].empty?
|
162
|
-
extract_environment_variables!
|
163
|
-
|
164
|
-
options[:actions].concat(args)
|
165
|
-
|
166
|
-
password = options.has_key?(:password)
|
167
|
-
options[:password] = Proc.new { self.class.password_prompt }
|
168
|
-
options[:password] = options[:password].call if password
|
169
|
-
end
|
170
|
-
|
171
|
-
# Extracts name=value pairs from the remaining command-line arguments
|
172
|
-
# and assigns them as environment variables.
|
173
|
-
def extract_environment_variables! #:nodoc:
|
174
|
-
args.delete_if do |arg|
|
175
|
-
next unless arg.match(/^(\w+)=(.*)$/)
|
176
|
-
ENV[$1] = $2
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
# Looks for a default recipe file in the current directory.
|
181
|
-
def look_for_default_recipe_file! #:nodoc:
|
182
|
-
current = Dir.pwd
|
183
|
-
|
184
|
-
loop do
|
185
|
-
%w(Capfile capfile).each do |file|
|
186
|
-
if File.file?(file)
|
187
|
-
options[:recipes] << file
|
188
|
-
@logger.info "Using recipes from #{File.join(current,file)}"
|
189
|
-
return
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
pwd = Dir.pwd
|
194
|
-
Dir.chdir("..")
|
195
|
-
break if pwd == Dir.pwd # if changing the directory made no difference, then we're at the top
|
196
|
-
end
|
197
|
-
|
198
|
-
Dir.chdir(current)
|
199
|
-
end
|
200
|
-
|
201
|
-
def default_sysconf #:nodoc:
|
202
|
-
File.join(sysconf_directory, "capistrano.conf")
|
203
|
-
end
|
204
|
-
|
205
|
-
def default_dotfile #:nodoc:
|
206
|
-
File.join(home_directory, ".caprc")
|
207
|
-
end
|
208
|
-
|
209
|
-
def sysconf_directory #:nodoc:
|
210
|
-
# TODO if anyone cares, feel free to submit a patch that uses a more
|
211
|
-
# appropriate location for this file in Windows.
|
212
|
-
ENV["SystemRoot"] || '/etc'
|
213
|
-
end
|
214
|
-
|
215
|
-
def home_directory #:nodoc:
|
216
|
-
ENV["HOME"] ||
|
217
|
-
(ENV["HOMEPATH"] && "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}") ||
|
218
|
-
"/"
|
219
|
-
end
|
220
|
-
|
221
|
-
def coerce_variable_types!
|
222
|
-
[:pre_vars, :vars].each do |collection|
|
223
|
-
options[collection].keys.each do |key|
|
224
|
-
options[collection][key] = coerce_variable(options[collection][key])
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
def coerce_variable(value)
|
230
|
-
case value
|
231
|
-
when /^"(.*)"$/ then $1
|
232
|
-
when /^'(.*)'$/ then $1
|
233
|
-
when /^\d+$/ then value.to_i
|
234
|
-
when /^\d+\.\d*$/ then value.to_f
|
235
|
-
when "true" then true
|
236
|
-
when "false" then false
|
237
|
-
when "nil" then nil
|
238
|
-
else value
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
end
|