capistrano 2.15.11 → 3.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +17 -8
  3. data/Gemfile +1 -12
  4. data/LICENSE.txt +18 -0
  5. data/README.md +65 -68
  6. data/Rakefile +4 -10
  7. data/bin/cap +2 -3
  8. data/bin/capify +7 -91
  9. data/capistrano.gemspec +20 -34
  10. data/lib/Capfile +2 -0
  11. data/lib/capistrano/application.rb +28 -0
  12. data/lib/capistrano/bundler.rb +1 -0
  13. data/lib/capistrano/configuration/question.rb +42 -0
  14. data/lib/capistrano/configuration/server.rb +24 -0
  15. data/lib/capistrano/configuration/servers.rb +43 -95
  16. data/lib/capistrano/configuration.rb +81 -44
  17. data/lib/capistrano/console.rb +1 -0
  18. data/lib/capistrano/defaults.rb +11 -0
  19. data/lib/capistrano/deploy.rb +3 -0
  20. data/lib/capistrano/dotfile.rb +3 -0
  21. data/lib/capistrano/dsl/env.rb +57 -0
  22. data/lib/capistrano/dsl/paths.rb +74 -0
  23. data/lib/capistrano/dsl/stages.rb +15 -0
  24. data/lib/capistrano/dsl/task_enhancements.rb +15 -0
  25. data/lib/capistrano/dsl.rb +38 -0
  26. data/lib/capistrano/git.rb +1 -0
  27. data/lib/capistrano/i18n.rb +33 -0
  28. data/lib/capistrano/install.rb +1 -0
  29. data/lib/capistrano/setup.rb +17 -0
  30. data/lib/capistrano/tasks/bundler.rake +13 -0
  31. data/lib/capistrano/tasks/console.rake +21 -0
  32. data/lib/capistrano/tasks/deploy.rake +153 -0
  33. data/lib/capistrano/tasks/framework.rake +45 -0
  34. data/lib/capistrano/tasks/git.rake +65 -0
  35. data/lib/capistrano/tasks/install.rake +39 -0
  36. data/lib/capistrano/templates/Capfile +43 -0
  37. data/lib/capistrano/templates/deploy.rb.erb +17 -0
  38. data/lib/capistrano/templates/stage.rb.erb +20 -0
  39. data/lib/capistrano/version.rb +1 -11
  40. data/lib/capistrano.rb +9 -3
  41. data/spec/lib/capistrano/configuration/question_spec.rb +54 -0
  42. data/spec/lib/capistrano/configuration/server_spec.rb +48 -0
  43. data/spec/lib/capistrano/configuration/servers_spec.rb +79 -0
  44. data/spec/lib/capistrano/configuration_spec.rb +80 -0
  45. data/spec/lib/capistrano/dsl/env_spec.rb +83 -0
  46. data/spec/lib/capistrano/dsl/paths_spec.rb +69 -0
  47. data/spec/lib/capistrano/dsl_spec.rb +51 -0
  48. data/spec/lib/capistrano_spec.rb +8 -0
  49. data/spec/spec_helper.rb +14 -0
  50. metadata +89 -215
  51. data/.travis.yml +0 -9
  52. data/CHANGELOG +0 -1203
  53. data/lib/capistrano/callback.rb +0 -45
  54. data/lib/capistrano/cli/execute.rb +0 -85
  55. data/lib/capistrano/cli/help.rb +0 -125
  56. data/lib/capistrano/cli/help.txt +0 -81
  57. data/lib/capistrano/cli/options.rb +0 -243
  58. data/lib/capistrano/cli/ui.rb +0 -40
  59. data/lib/capistrano/cli.rb +0 -47
  60. data/lib/capistrano/command.rb +0 -303
  61. data/lib/capistrano/configuration/actions/file_transfer.rb +0 -50
  62. data/lib/capistrano/configuration/actions/inspect.rb +0 -46
  63. data/lib/capistrano/configuration/actions/invocation.rb +0 -329
  64. data/lib/capistrano/configuration/alias_task.rb +0 -26
  65. data/lib/capistrano/configuration/callbacks.rb +0 -147
  66. data/lib/capistrano/configuration/connections.rb +0 -237
  67. data/lib/capistrano/configuration/execution.rb +0 -142
  68. data/lib/capistrano/configuration/loading.rb +0 -205
  69. data/lib/capistrano/configuration/log_formatters.rb +0 -75
  70. data/lib/capistrano/configuration/namespaces.rb +0 -223
  71. data/lib/capistrano/configuration/roles.rb +0 -83
  72. data/lib/capistrano/configuration/variables.rb +0 -127
  73. data/lib/capistrano/errors.rb +0 -19
  74. data/lib/capistrano/ext/multistage.rb +0 -67
  75. data/lib/capistrano/ext/string.rb +0 -5
  76. data/lib/capistrano/extensions.rb +0 -57
  77. data/lib/capistrano/fix_rake_deprecated_dsl.rb +0 -8
  78. data/lib/capistrano/logger.rb +0 -166
  79. data/lib/capistrano/processable.rb +0 -55
  80. data/lib/capistrano/recipes/compat.rb +0 -32
  81. data/lib/capistrano/recipes/deploy/assets.rb +0 -202
  82. data/lib/capistrano/recipes/deploy/dependencies.rb +0 -44
  83. data/lib/capistrano/recipes/deploy/local_dependency.rb +0 -54
  84. data/lib/capistrano/recipes/deploy/remote_dependency.rb +0 -117
  85. data/lib/capistrano/recipes/deploy/scm/accurev.rb +0 -169
  86. data/lib/capistrano/recipes/deploy/scm/base.rb +0 -200
  87. data/lib/capistrano/recipes/deploy/scm/bzr.rb +0 -86
  88. data/lib/capistrano/recipes/deploy/scm/cvs.rb +0 -153
  89. data/lib/capistrano/recipes/deploy/scm/darcs.rb +0 -96
  90. data/lib/capistrano/recipes/deploy/scm/git.rb +0 -299
  91. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +0 -137
  92. data/lib/capistrano/recipes/deploy/scm/none.rb +0 -55
  93. data/lib/capistrano/recipes/deploy/scm/perforce.rb +0 -152
  94. data/lib/capistrano/recipes/deploy/scm/subversion.rb +0 -121
  95. data/lib/capistrano/recipes/deploy/scm.rb +0 -19
  96. data/lib/capistrano/recipes/deploy/strategy/base.rb +0 -92
  97. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +0 -20
  98. data/lib/capistrano/recipes/deploy/strategy/copy.rb +0 -338
  99. data/lib/capistrano/recipes/deploy/strategy/export.rb +0 -20
  100. data/lib/capistrano/recipes/deploy/strategy/remote.rb +0 -52
  101. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +0 -57
  102. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +0 -21
  103. data/lib/capistrano/recipes/deploy/strategy.rb +0 -20
  104. data/lib/capistrano/recipes/deploy.rb +0 -625
  105. data/lib/capistrano/recipes/standard.rb +0 -37
  106. data/lib/capistrano/recipes/templates/maintenance.rhtml +0 -53
  107. data/lib/capistrano/role.rb +0 -102
  108. data/lib/capistrano/server_definition.rb +0 -56
  109. data/lib/capistrano/shell.rb +0 -265
  110. data/lib/capistrano/ssh.rb +0 -95
  111. data/lib/capistrano/task_definition.rb +0 -77
  112. data/lib/capistrano/transfer.rb +0 -218
  113. data/test/cli/execute_test.rb +0 -132
  114. data/test/cli/help_test.rb +0 -165
  115. data/test/cli/options_test.rb +0 -329
  116. data/test/cli/ui_test.rb +0 -28
  117. data/test/cli_test.rb +0 -17
  118. data/test/command_test.rb +0 -322
  119. data/test/configuration/actions/file_transfer_test.rb +0 -61
  120. data/test/configuration/actions/inspect_test.rb +0 -76
  121. data/test/configuration/actions/invocation_test.rb +0 -306
  122. data/test/configuration/alias_task_test.rb +0 -118
  123. data/test/configuration/callbacks_test.rb +0 -201
  124. data/test/configuration/connections_test.rb +0 -439
  125. data/test/configuration/execution_test.rb +0 -175
  126. data/test/configuration/loading_test.rb +0 -148
  127. data/test/configuration/namespace_dsl_test.rb +0 -332
  128. data/test/configuration/roles_test.rb +0 -157
  129. data/test/configuration/servers_test.rb +0 -183
  130. data/test/configuration/variables_test.rb +0 -190
  131. data/test/configuration_test.rb +0 -77
  132. data/test/deploy/local_dependency_test.rb +0 -76
  133. data/test/deploy/remote_dependency_test.rb +0 -146
  134. data/test/deploy/scm/accurev_test.rb +0 -23
  135. data/test/deploy/scm/base_test.rb +0 -55
  136. data/test/deploy/scm/bzr_test.rb +0 -51
  137. data/test/deploy/scm/darcs_test.rb +0 -37
  138. data/test/deploy/scm/git_test.rb +0 -274
  139. data/test/deploy/scm/mercurial_test.rb +0 -134
  140. data/test/deploy/scm/none_test.rb +0 -35
  141. data/test/deploy/scm/perforce_test.rb +0 -23
  142. data/test/deploy/scm/subversion_test.rb +0 -68
  143. data/test/deploy/strategy/copy_test.rb +0 -360
  144. data/test/extensions_test.rb +0 -69
  145. data/test/fixtures/cli_integration.rb +0 -5
  146. data/test/fixtures/config.rb +0 -5
  147. data/test/fixtures/custom.rb +0 -3
  148. data/test/logger_formatting_test.rb +0 -149
  149. data/test/logger_test.rb +0 -134
  150. data/test/recipes_test.rb +0 -25
  151. data/test/role_test.rb +0 -11
  152. data/test/server_definition_test.rb +0 -121
  153. data/test/shell_test.rb +0 -96
  154. data/test/ssh_test.rb +0 -113
  155. data/test/task_definition_test.rb +0 -117
  156. data/test/transfer_test.rb +0 -168
  157. data/test/utils.rb +0 -37
  158. data/test/version_test.rb +0 -11
@@ -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
@@ -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? )
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
@@ -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
@@ -1,40 +0,0 @@
1
- require 'highline'
2
-
3
- # work around problem where HighLine detects an eof on $stdin and raises an
4
- # error.
5
- HighLine.track_eof = false
6
-
7
- module Capistrano
8
- class CLI
9
- module UI
10
- def self.included(base) #:nodoc:
11
- base.extend(ClassMethods)
12
- end
13
-
14
- module ClassMethods
15
- # Return the object that provides UI-specific methods, such as prompts
16
- # and more.
17
- def ui
18
- @ui ||= HighLine.new
19
- end
20
-
21
- # Prompt for a password using echo suppression.
22
- def password_prompt(prompt="Password: ")
23
- ui.ask(prompt) { |q| q.echo = false }
24
- end
25
-
26
- # Debug mode prompt
27
- def debug_prompt(cmd)
28
- ui.say("Preparing to execute command: #{cmd}")
29
- prompt = "Execute ([Yes], No, Abort) "
30
- ui.ask("#{prompt}? ") do |q|
31
- q.overwrite = false
32
- q.default = 'y'
33
- q.validate = /(y(es)?)|(no?)|(a(bort)?|\n)/i
34
- q.responses[:not_valid] = prompt
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,47 +0,0 @@
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 -f 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, The above snippet, redone using the
24
- # Configuration class directly, would look like:
25
- #
26
- # require 'capistrano'
27
- # require 'capistrano/cli'
28
- # config = Capistrano::Configuration.new
29
- # config.logger.level = Capistrano::Logger::TRACE
30
- # config.set(:password) { Capistrano::CLI.password_prompt }
31
- # config.load "config/deploy"
32
- # config.update_code
33
- #
34
- # There may be times that you want/need the additional control offered by
35
- # manipulating the Configuration directly, but generally interfacing with
36
- # the CLI class is recommended.
37
- def initialize(args)
38
- @args = args.dup
39
- $stdout.sync = true # so that Net::SSH prompts show up
40
- end
41
-
42
- # Mix-in the actual behavior
43
- include Execute, Options, UI
44
- include Help # needs to be included last, because it overrides some methods
45
-
46
- end
47
- end