wulffeld-capistrano 2.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/CHANGELOG.rdoc +761 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +66 -0
  4. data/Rakefile +34 -0
  5. data/bin/cap +4 -0
  6. data/bin/capify +78 -0
  7. data/examples/sample.rb +14 -0
  8. data/lib/capistrano.rb +2 -0
  9. data/lib/capistrano/callback.rb +45 -0
  10. data/lib/capistrano/cli.rb +47 -0
  11. data/lib/capistrano/cli/execute.rb +84 -0
  12. data/lib/capistrano/cli/help.rb +125 -0
  13. data/lib/capistrano/cli/help.txt +75 -0
  14. data/lib/capistrano/cli/options.rb +224 -0
  15. data/lib/capistrano/cli/ui.rb +40 -0
  16. data/lib/capistrano/command.rb +283 -0
  17. data/lib/capistrano/configuration.rb +43 -0
  18. data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
  19. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  20. data/lib/capistrano/configuration/actions/invocation.rb +293 -0
  21. data/lib/capistrano/configuration/callbacks.rb +148 -0
  22. data/lib/capistrano/configuration/connections.rb +200 -0
  23. data/lib/capistrano/configuration/execution.rb +132 -0
  24. data/lib/capistrano/configuration/loading.rb +197 -0
  25. data/lib/capistrano/configuration/namespaces.rb +197 -0
  26. data/lib/capistrano/configuration/roles.rb +73 -0
  27. data/lib/capistrano/configuration/servers.rb +85 -0
  28. data/lib/capistrano/configuration/variables.rb +127 -0
  29. data/lib/capistrano/errors.rb +15 -0
  30. data/lib/capistrano/extensions.rb +57 -0
  31. data/lib/capistrano/logger.rb +59 -0
  32. data/lib/capistrano/processable.rb +53 -0
  33. data/lib/capistrano/recipes/compat.rb +32 -0
  34. data/lib/capistrano/recipes/deploy.rb +562 -0
  35. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  36. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  37. data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
  38. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  39. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  40. data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
  41. data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
  42. data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
  43. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  44. data/lib/capistrano/recipes/deploy/scm/git.rb +302 -0
  45. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  46. data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
  47. data/lib/capistrano/recipes/deploy/scm/perforce.rb +133 -0
  48. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  49. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  50. data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
  51. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  52. data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
  53. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  54. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  55. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
  56. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  57. data/lib/capistrano/recipes/standard.rb +37 -0
  58. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  59. data/lib/capistrano/recipes/upgrade.rb +33 -0
  60. data/lib/capistrano/role.rb +102 -0
  61. data/lib/capistrano/server_definition.rb +56 -0
  62. data/lib/capistrano/shell.rb +260 -0
  63. data/lib/capistrano/ssh.rb +99 -0
  64. data/lib/capistrano/task_definition.rb +70 -0
  65. data/lib/capistrano/transfer.rb +216 -0
  66. data/lib/capistrano/version.rb +18 -0
  67. data/setup.rb +1346 -0
  68. data/test/cli/execute_test.rb +132 -0
  69. data/test/cli/help_test.rb +165 -0
  70. data/test/cli/options_test.rb +317 -0
  71. data/test/cli/ui_test.rb +28 -0
  72. data/test/cli_test.rb +17 -0
  73. data/test/command_test.rb +286 -0
  74. data/test/configuration/actions/file_transfer_test.rb +61 -0
  75. data/test/configuration/actions/inspect_test.rb +65 -0
  76. data/test/configuration/actions/invocation_test.rb +224 -0
  77. data/test/configuration/callbacks_test.rb +220 -0
  78. data/test/configuration/connections_test.rb +349 -0
  79. data/test/configuration/execution_test.rb +175 -0
  80. data/test/configuration/loading_test.rb +132 -0
  81. data/test/configuration/namespace_dsl_test.rb +311 -0
  82. data/test/configuration/roles_test.rb +144 -0
  83. data/test/configuration/servers_test.rb +121 -0
  84. data/test/configuration/variables_test.rb +184 -0
  85. data/test/configuration_test.rb +88 -0
  86. data/test/deploy/local_dependency_test.rb +76 -0
  87. data/test/deploy/remote_dependency_test.rb +114 -0
  88. data/test/deploy/scm/accurev_test.rb +23 -0
  89. data/test/deploy/scm/base_test.rb +55 -0
  90. data/test/deploy/scm/git_test.rb +167 -0
  91. data/test/deploy/scm/mercurial_test.rb +129 -0
  92. data/test/deploy/strategy/copy_test.rb +258 -0
  93. data/test/extensions_test.rb +69 -0
  94. data/test/fixtures/cli_integration.rb +5 -0
  95. data/test/fixtures/config.rb +5 -0
  96. data/test/fixtures/custom.rb +3 -0
  97. data/test/logger_test.rb +123 -0
  98. data/test/role_test.rb +11 -0
  99. data/test/server_definition_test.rb +121 -0
  100. data/test/shell_test.rb +90 -0
  101. data/test/ssh_test.rb +104 -0
  102. data/test/task_definition_test.rb +101 -0
  103. data/test/transfer_test.rb +160 -0
  104. data/test/utils.rb +38 -0
  105. metadata +207 -0
data/Manifest ADDED
@@ -0,0 +1,104 @@
1
+ bin/cap
2
+ bin/capify
3
+ CHANGELOG.rdoc
4
+ examples/sample.rb
5
+ lib/capistrano/callback.rb
6
+ lib/capistrano/cli/execute.rb
7
+ lib/capistrano/cli/help.rb
8
+ lib/capistrano/cli/help.txt
9
+ lib/capistrano/cli/options.rb
10
+ lib/capistrano/cli/ui.rb
11
+ lib/capistrano/cli.rb
12
+ lib/capistrano/command.rb
13
+ lib/capistrano/configuration/actions/file_transfer.rb
14
+ lib/capistrano/configuration/actions/inspect.rb
15
+ lib/capistrano/configuration/actions/invocation.rb
16
+ lib/capistrano/configuration/callbacks.rb
17
+ lib/capistrano/configuration/connections.rb
18
+ lib/capistrano/configuration/execution.rb
19
+ lib/capistrano/configuration/loading.rb
20
+ lib/capistrano/configuration/namespaces.rb
21
+ lib/capistrano/configuration/roles.rb
22
+ lib/capistrano/configuration/servers.rb
23
+ lib/capistrano/configuration/variables.rb
24
+ lib/capistrano/configuration.rb
25
+ lib/capistrano/errors.rb
26
+ lib/capistrano/extensions.rb
27
+ lib/capistrano/logger.rb
28
+ lib/capistrano/processable.rb
29
+ lib/capistrano/recipes/compat.rb
30
+ lib/capistrano/recipes/deploy/dependencies.rb
31
+ lib/capistrano/recipes/deploy/local_dependency.rb
32
+ lib/capistrano/recipes/deploy/remote_dependency.rb
33
+ lib/capistrano/recipes/deploy/scm/accurev.rb
34
+ lib/capistrano/recipes/deploy/scm/base.rb
35
+ lib/capistrano/recipes/deploy/scm/bzr.rb
36
+ lib/capistrano/recipes/deploy/scm/cvs.rb
37
+ lib/capistrano/recipes/deploy/scm/darcs.rb
38
+ lib/capistrano/recipes/deploy/scm/git.rb
39
+ lib/capistrano/recipes/deploy/scm/mercurial.rb
40
+ lib/capistrano/recipes/deploy/scm/none.rb
41
+ lib/capistrano/recipes/deploy/scm/perforce.rb
42
+ lib/capistrano/recipes/deploy/scm/subversion.rb
43
+ lib/capistrano/recipes/deploy/scm.rb
44
+ lib/capistrano/recipes/deploy/strategy/base.rb
45
+ lib/capistrano/recipes/deploy/strategy/checkout.rb
46
+ lib/capistrano/recipes/deploy/strategy/copy.rb
47
+ lib/capistrano/recipes/deploy/strategy/export.rb
48
+ lib/capistrano/recipes/deploy/strategy/remote.rb
49
+ lib/capistrano/recipes/deploy/strategy/remote_cache.rb
50
+ lib/capistrano/recipes/deploy/strategy.rb
51
+ lib/capistrano/recipes/deploy/templates/maintenance.rhtml
52
+ lib/capistrano/recipes/deploy.rb
53
+ lib/capistrano/recipes/standard.rb
54
+ lib/capistrano/recipes/templates/maintenance.rhtml
55
+ lib/capistrano/recipes/upgrade.rb
56
+ lib/capistrano/role.rb
57
+ lib/capistrano/server_definition.rb
58
+ lib/capistrano/shell.rb
59
+ lib/capistrano/ssh.rb
60
+ lib/capistrano/task_definition.rb
61
+ lib/capistrano/transfer.rb
62
+ lib/capistrano/version.rb
63
+ lib/capistrano.rb
64
+ Rakefile
65
+ README.rdoc
66
+ setup.rb
67
+ test/cli/execute_test.rb
68
+ test/cli/help_test.rb
69
+ test/cli/options_test.rb
70
+ test/cli/ui_test.rb
71
+ test/cli_test.rb
72
+ test/command_test.rb
73
+ test/configuration/actions/file_transfer_test.rb
74
+ test/configuration/actions/inspect_test.rb
75
+ test/configuration/actions/invocation_test.rb
76
+ test/configuration/callbacks_test.rb
77
+ test/configuration/connections_test.rb
78
+ test/configuration/execution_test.rb
79
+ test/configuration/loading_test.rb
80
+ test/configuration/namespace_dsl_test.rb
81
+ test/configuration/roles_test.rb
82
+ test/configuration/servers_test.rb
83
+ test/configuration/variables_test.rb
84
+ test/configuration_test.rb
85
+ test/deploy/local_dependency_test.rb
86
+ test/deploy/remote_dependency_test.rb
87
+ test/deploy/scm/accurev_test.rb
88
+ test/deploy/scm/base_test.rb
89
+ test/deploy/scm/git_test.rb
90
+ test/deploy/scm/mercurial_test.rb
91
+ test/deploy/strategy/copy_test.rb
92
+ test/extensions_test.rb
93
+ test/fixtures/cli_integration.rb
94
+ test/fixtures/config.rb
95
+ test/fixtures/custom.rb
96
+ test/logger_test.rb
97
+ test/role_test.rb
98
+ test/server_definition_test.rb
99
+ test/shell_test.rb
100
+ test/ssh_test.rb
101
+ test/task_definition_test.rb
102
+ test/transfer_test.rb
103
+ test/utils.rb
104
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
1
+ = Capistrano
2
+
3
+ Capistrano is a utility and framework for executing commands in parallel on multiple remote machines, via SSH. It uses a simple DSL (borrowed in part from Rake, http://rake.rubyforge.org/) that allows you to define _tasks_, which may be applied to machines in certain roles. It also supports tunneling connections via some gateway machine to allow operations to be performed behind VPN's and firewalls.
4
+
5
+ Capistrano was originally designed to simplify and automate deployment of web applications to distributed environments, and originally came bundled with a set of tasks designed for deploying Rails applications. The deployment tasks are now (as of Capistrano 2.0) opt-in and require clients to explicitly put
6
+ "load 'deploy'" in their recipes.
7
+
8
+ == DEPENDENCIES
9
+
10
+ * Net::SSH v2 (http://net-ssh.rubyforge.org)
11
+ * Net::SFTP v2 (http://net-ssh.rubyforge.org)
12
+ * Net::SCP v1 (http://net-ssh.rubyforge.org)
13
+ * Net::SSH::Gateway v1 (http://net-ssh.rubyforge.org)
14
+ * HighLine (http://highline.rubyforge.org)
15
+
16
+ If you want to run the tests, you'll also need to have the following dependencies installed:
17
+
18
+ * Echoe (for the Rakefile)
19
+ * Mocha (http://mocha.rubyforge.org)
20
+
21
+ == ASSUMPTIONS
22
+
23
+ Capistrano is "opinionated software", which means it has very firm ideas about how things ought to be done, and tries to force those ideas on you. Some of the assumptions behind these opinions are:
24
+
25
+ * You are using SSH to access the remote servers.
26
+ * You either have the same password to all target machines, or you have public keys in place to allow passwordless access to them.
27
+
28
+ Do not expect these assumptions to change.
29
+
30
+ == USAGE
31
+
32
+ In general, you'll use Capistrano as follows:
33
+
34
+ * Create a recipe file ("capfile" or "Capfile").
35
+ * Use the +cap+ script to execute your recipe.
36
+
37
+ Use the +cap+ script as follows:
38
+
39
+ cap sometask
40
+
41
+ By default, the script will look for a file called one of +capfile+ or +Capfile+. The +someaction+ text indicates which task to execute. You can do "cap -h" to see all the available options and "cap -T" to see all the available tasks.
42
+
43
+ == LICENSE:
44
+
45
+ (The MIT License)
46
+
47
+ Copyright (c) 2005-2008 Jamis Buck <jamis@37signals.com>
48
+
49
+ Permission is hereby granted, free of charge, to any person obtaining
50
+ a copy of this software and associated documentation files (the
51
+ 'Software'), to deal in the Software without restriction, including
52
+ without limitation the rights to use, copy, modify, merge, publish,
53
+ distribute, sublicense, and/or sell copies of the Software, and to
54
+ permit persons to whom the Software is furnished to do so, subject to
55
+ the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be
58
+ included in all copies or substantial portions of the Software.
59
+
60
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
61
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
63
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
64
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
65
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
66
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require "./lib/capistrano/version"
2
+
3
+ begin
4
+ require 'echoe'
5
+ rescue LoadError
6
+ abort "You'll need to have `echoe' installed to use Capistrano's Rakefile"
7
+ end
8
+
9
+ version = Capistrano::Version::STRING.dup
10
+ if ENV['SNAPSHOT'].to_i == 1
11
+ version << "." << Time.now.utc.strftime("%Y%m%d%H%M%S")
12
+ end
13
+
14
+ Echoe.new('capistrano', version) do |p|
15
+ p.changelog = "CHANGELOG.rdoc"
16
+
17
+ p.author = "Jamis Buck"
18
+ p.email = "jamis@jamisbuck.org"
19
+
20
+ p.summary = <<-DESC.strip.gsub(/\n\s+/, " ")
21
+ Capistrano is a utility and framework for executing commands in parallel
22
+ on multiple remote machines, via SSH.
23
+ DESC
24
+
25
+ p.url = "http://www.capify.org"
26
+ p.need_zip = true
27
+ p.rdoc_pattern = /^(lib|README.rdoc|CHANGELOG.rdoc)/
28
+
29
+ p.dependencies = ["net-ssh >=2.0.10",
30
+ "net-sftp >=2.0.0",
31
+ "net-scp >=1.0.0",
32
+ "net-ssh-gateway >=1.0.0",
33
+ "highline"]
34
+ end
data/bin/cap ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'capistrano/cli'
4
+ Capistrano::CLI.execute
data/bin/capify ADDED
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ OptionParser.new do |opts|
6
+ opts.banner = "Usage: #{File.basename($0)} [path]"
7
+
8
+ opts.on("-h", "--help", "Displays this help info") do
9
+ puts opts
10
+ exit 0
11
+ end
12
+
13
+ begin
14
+ opts.parse!(ARGV)
15
+ rescue OptionParser::ParseError => e
16
+ warn e.message
17
+ puts opts
18
+ exit 1
19
+ end
20
+ end
21
+
22
+ if ARGV.empty?
23
+ abort "Please specify the directory to capify, e.g. `#{File.basename($0)} .'"
24
+ elsif !File.exists?(ARGV.first)
25
+ abort "`#{ARGV.first}' does not exist."
26
+ elsif !File.directory?(ARGV.first)
27
+ abort "`#{ARGV.first}' is not a directory."
28
+ elsif ARGV.length > 1
29
+ abort "Too many arguments; please specify only the directory to capify."
30
+ end
31
+
32
+ def unindent(string)
33
+ indentation = string[/\A\s*/]
34
+ string.strip.gsub(/^#{indentation}/, "")
35
+ end
36
+
37
+ files = {
38
+ "Capfile" => unindent(<<-FILE),
39
+ load 'deploy' if respond_to?(:namespace) # cap2 differentiator
40
+ Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
41
+ load 'config/deploy'
42
+ FILE
43
+
44
+ "config/deploy.rb" => unindent(<<-FILE),
45
+ set :application, "set your application name here"
46
+ set :repository, "set your repository location here"
47
+
48
+ # If you aren't deploying to /u/apps/\#{application} on the target
49
+ # servers (which is the default), you can specify the actual location
50
+ # via the :deploy_to variable:
51
+ # set :deploy_to, "/var/www/\#{application}"
52
+
53
+ # If you aren't using Subversion to manage your source code, specify
54
+ # your SCM below:
55
+ # set :scm, :subversion
56
+
57
+ role :app, "your app-server here"
58
+ role :web, "your web-server here"
59
+ role :db, "your db-server here", :primary => true
60
+ FILE
61
+ }
62
+
63
+ base = ARGV.shift
64
+ files.each do |file, content|
65
+ file = File.join(base, file)
66
+ if File.exists?(file)
67
+ warn "[skip] `#{file}' already exists"
68
+ elsif File.exists?(file.downcase)
69
+ warn "[skip] `#{file.downcase}' exists, which could conflict with `#{file}'"
70
+ elsif !File.exists?(File.dirname(file))
71
+ warn "[skip] directory `#{File.dirname(file)}' does not exist"
72
+ else
73
+ puts "[add] writing `#{file}'"
74
+ File.open(file, "w") { |f| f.write(content) }
75
+ end
76
+ end
77
+
78
+ puts "[done] capified!"
@@ -0,0 +1,14 @@
1
+ # set :user, "flippy"
2
+ # set :password, "hello-flippy"
3
+ # set :gateway, "gateway.example.com"
4
+
5
+ role :web, "web1.example.com"
6
+ role :app, "app1.example.com", "app2.example.com"
7
+
8
+ desc <<-DESC
9
+ This is a sample task. It is only intended to be used as a demonstration of \
10
+ how you can define your own tasks.
11
+ DESC
12
+ task :sample_task, :roles => :app do
13
+ run "ls -l"
14
+ end
data/lib/capistrano.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'capistrano/configuration'
2
+ require 'capistrano/extensions'
@@ -0,0 +1,45 @@
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
@@ -0,0 +1,47 @@
1
+ require 'capistrano'
2
+ require 'capistrano/cli/execute'
3
+ require 'capistrano/cli/help'
4
+ require 'capistrano/cli/options'
5
+ require 'capistrano/cli/ui'
6
+
7
+ module Capistrano
8
+ # The CLI class encapsulates the behavior of capistrano when it is invoked
9
+ # as a command-line utility. This allows other programs to embed Capistrano
10
+ # and preserve its command-line semantics.
11
+ class CLI
12
+ # The array of (unparsed) command-line options
13
+ attr_reader :args
14
+
15
+ # Create a new CLI instance using the given array of command-line parameters
16
+ # to initialize it. By default, +ARGV+ is used, but you can specify a
17
+ # different set of parameters (such as when embedded cap in a program):
18
+ #
19
+ # require 'capistrano/cli'
20
+ # Capistrano::CLI.parse(%w(-vvvv -r config/deploy update_code)).execute!
21
+ #
22
+ # Note that you can also embed cap directly by creating a new Configuration
23
+ # instance and setting it up, but you'll often wind up duplicating logic
24
+ # defined in the CLI class. The above snippet, redone using the Configuration
25
+ # class directly, would look like:
26
+ #
27
+ # require 'capistrano'
28
+ # require 'capistrano/cli'
29
+ # config = Capistrano::Configuration.new
30
+ # config.logger_level = Capistrano::Logger::TRACE
31
+ # config.set(:password) { Capistrano::CLI.password_prompt }
32
+ # config.load "config/deploy"
33
+ # config.update_code
34
+ #
35
+ # There may be times that you want/need the additional control offered by
36
+ # manipulating the Configuration directly, but generally interfacing with
37
+ # the CLI class is recommended.
38
+ def initialize(args)
39
+ @args = args.dup
40
+ $stdout.sync = true # so that Net::SSH prompts show up
41
+ end
42
+
43
+ # Mix-in the actual behavior
44
+ include Execute, Options, UI
45
+ include Help # needs to be included last, because it overrides some methods
46
+ end
47
+ end
@@ -0,0 +1,84 @@
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
25
+ config.debug = options[:debug]
26
+ config.dry_run = options[:dry_run]
27
+ config.logger.level = options[:verbose]
28
+
29
+ set_pre_vars(config)
30
+ load_recipes(config)
31
+
32
+ config.trigger(:load)
33
+ execute_requested_actions(config)
34
+ config.trigger(:exit)
35
+
36
+ config
37
+ rescue Exception => error
38
+ handle_error(error)
39
+ end
40
+
41
+ def execute_requested_actions(config)
42
+ Array(options[:vars]).each { |name, value| config.set(name, value) }
43
+
44
+ Array(options[:actions]).each do |action|
45
+ config.find_and_execute_task(action, :before => :start, :after => :finish)
46
+ end
47
+ end
48
+
49
+ def set_pre_vars(config) #:nodoc:
50
+ config.set :password, options[:password]
51
+ Array(options[:pre_vars]).each { |name, value| config.set(name, value) }
52
+ end
53
+
54
+ def load_recipes(config) #:nodoc:
55
+ # load the standard recipe definition
56
+ config.load "standard"
57
+
58
+ # load systemwide config/recipe definition
59
+ config.load(options[:sysconf]) if options[:sysconf] && File.file?(options[:sysconf])
60
+
61
+ # load user config/recipe definition
62
+ config.load(options[:dotfile]) if options[:dotfile] && File.file?(options[:dotfile])
63
+
64
+ Array(options[:recipes]).each { |recipe| config.load(recipe) }
65
+ end
66
+
67
+ # Primarily useful for testing, but subclasses of CLI could conceivably
68
+ # override this method to return a Configuration subclass or replacement.
69
+ def instantiate_configuration #:nodoc:
70
+ Capistrano::Configuration.new
71
+ end
72
+
73
+ def handle_error(error) #:nodoc:
74
+ case error
75
+ when Net::SSH::AuthenticationFailed
76
+ abort "authentication failed for `#{error.message}'"
77
+ when Capistrano::Error
78
+ abort(error.message)
79
+ else raise error
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end