capistrano-edge 2.5.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/CHANGELOG.rdoc +770 -0
  2. data/Manifest +104 -0
  3. data/README.rdoc +66 -0
  4. data/Rakefile +35 -0
  5. data/bin/cap +4 -0
  6. data/bin/capify +95 -0
  7. data/capistrano.gemspec +51 -0
  8. data/examples/sample.rb +14 -0
  9. data/lib/capistrano.rb +2 -0
  10. data/lib/capistrano/callback.rb +45 -0
  11. data/lib/capistrano/cli.rb +47 -0
  12. data/lib/capistrano/cli/execute.rb +84 -0
  13. data/lib/capistrano/cli/help.rb +125 -0
  14. data/lib/capistrano/cli/help.txt +75 -0
  15. data/lib/capistrano/cli/options.rb +224 -0
  16. data/lib/capistrano/cli/ui.rb +40 -0
  17. data/lib/capistrano/command.rb +283 -0
  18. data/lib/capistrano/configuration.rb +43 -0
  19. data/lib/capistrano/configuration/actions/file_transfer.rb +47 -0
  20. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  21. data/lib/capistrano/configuration/actions/invocation.rb +293 -0
  22. data/lib/capistrano/configuration/callbacks.rb +148 -0
  23. data/lib/capistrano/configuration/connections.rb +204 -0
  24. data/lib/capistrano/configuration/execution.rb +143 -0
  25. data/lib/capistrano/configuration/loading.rb +197 -0
  26. data/lib/capistrano/configuration/namespaces.rb +197 -0
  27. data/lib/capistrano/configuration/roles.rb +73 -0
  28. data/lib/capistrano/configuration/servers.rb +85 -0
  29. data/lib/capistrano/configuration/variables.rb +127 -0
  30. data/lib/capistrano/errors.rb +15 -0
  31. data/lib/capistrano/extensions.rb +57 -0
  32. data/lib/capistrano/logger.rb +59 -0
  33. data/lib/capistrano/processable.rb +53 -0
  34. data/lib/capistrano/recipes/compat.rb +32 -0
  35. data/lib/capistrano/recipes/deploy.rb +438 -0
  36. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  37. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  38. data/lib/capistrano/recipes/deploy/remote_dependency.rb +105 -0
  39. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  40. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  41. data/lib/capistrano/recipes/deploy/scm/base.rb +196 -0
  42. data/lib/capistrano/recipes/deploy/scm/bzr.rb +83 -0
  43. data/lib/capistrano/recipes/deploy/scm/cvs.rb +152 -0
  44. data/lib/capistrano/recipes/deploy/scm/darcs.rb +85 -0
  45. data/lib/capistrano/recipes/deploy/scm/git.rb +274 -0
  46. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  47. data/lib/capistrano/recipes/deploy/scm/none.rb +44 -0
  48. data/lib/capistrano/recipes/deploy/scm/perforce.rb +138 -0
  49. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  50. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  51. data/lib/capistrano/recipes/deploy/strategy/base.rb +79 -0
  52. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  53. data/lib/capistrano/recipes/deploy/strategy/copy.rb +210 -0
  54. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  55. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  56. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +56 -0
  57. data/lib/capistrano/recipes/deploy/templates/maintenance.rhtml +53 -0
  58. data/lib/capistrano/recipes/ext/rails-database-migrations.rb +50 -0
  59. data/lib/capistrano/recipes/ext/web-disable-enable.rb +40 -0
  60. data/lib/capistrano/recipes/standard.rb +37 -0
  61. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  62. data/lib/capistrano/recipes/upgrade.rb +33 -0
  63. data/lib/capistrano/role.rb +102 -0
  64. data/lib/capistrano/server_definition.rb +56 -0
  65. data/lib/capistrano/shell.rb +260 -0
  66. data/lib/capistrano/ssh.rb +99 -0
  67. data/lib/capistrano/task_definition.rb +70 -0
  68. data/lib/capistrano/transfer.rb +216 -0
  69. data/lib/capistrano/version.rb +18 -0
  70. data/setup.rb +1346 -0
  71. data/test/cli/execute_test.rb +132 -0
  72. data/test/cli/help_test.rb +165 -0
  73. data/test/cli/options_test.rb +317 -0
  74. data/test/cli/ui_test.rb +28 -0
  75. data/test/cli_test.rb +17 -0
  76. data/test/command_test.rb +286 -0
  77. data/test/configuration/actions/file_transfer_test.rb +61 -0
  78. data/test/configuration/actions/inspect_test.rb +65 -0
  79. data/test/configuration/actions/invocation_test.rb +224 -0
  80. data/test/configuration/callbacks_test.rb +220 -0
  81. data/test/configuration/connections_test.rb +349 -0
  82. data/test/configuration/execution_test.rb +175 -0
  83. data/test/configuration/loading_test.rb +132 -0
  84. data/test/configuration/namespace_dsl_test.rb +311 -0
  85. data/test/configuration/roles_test.rb +144 -0
  86. data/test/configuration/servers_test.rb +121 -0
  87. data/test/configuration/variables_test.rb +184 -0
  88. data/test/configuration_test.rb +88 -0
  89. data/test/deploy/local_dependency_test.rb +76 -0
  90. data/test/deploy/remote_dependency_test.rb +114 -0
  91. data/test/deploy/scm/accurev_test.rb +23 -0
  92. data/test/deploy/scm/base_test.rb +55 -0
  93. data/test/deploy/scm/git_test.rb +184 -0
  94. data/test/deploy/scm/mercurial_test.rb +129 -0
  95. data/test/deploy/scm/none_test.rb +35 -0
  96. data/test/deploy/strategy/copy_test.rb +258 -0
  97. data/test/extensions_test.rb +69 -0
  98. data/test/fixtures/cli_integration.rb +5 -0
  99. data/test/fixtures/config.rb +5 -0
  100. data/test/fixtures/custom.rb +3 -0
  101. data/test/logger_test.rb +123 -0
  102. data/test/role_test.rb +11 -0
  103. data/test/server_definition_test.rb +121 -0
  104. data/test/shell_test.rb +90 -0
  105. data/test/ssh_test.rb +104 -0
  106. data/test/task_definition_test.rb +101 -0
  107. data/test/transfer_test.rb +160 -0
  108. data/test/utils.rb +38 -0
  109. metadata +321 -0
@@ -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
@@ -0,0 +1,125 @@
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
@@ -0,0 +1,75 @@
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 '-n, --dry-run', :bold %>
32
+ 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.
33
+
34
+ <%= color '-p, --password', :bold %>
35
+ 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.
36
+
37
+ <%= color '-q, --quiet', :bold %>
38
+ Display only critical error messages. All other output is suppressed.
39
+
40
+ <%= color '-S, --set-before NAME=VALUE', :bold %>
41
+ 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.
42
+
43
+ <%= color '-s, --set NAME=VALUE', :bold %>
44
+ 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.
45
+
46
+ <%= color '-T, --tasks PATTERN', :bold %>
47
+ 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.
48
+
49
+ <%= color '-t, --tool', :bold %>
50
+ 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.)
51
+
52
+ <%= color '-V, --version', :bold %>
53
+ Shows the current Capistrano version number and exits.
54
+
55
+ <%= color '-v, --verbose', :bold %>
56
+ 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.
57
+
58
+ <%= color '-X, --skip-system-config', :bold %>
59
+ 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.
60
+
61
+ <%= color '-x, --skip-user-config', :bold %>
62
+ 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.
63
+
64
+ -----------------------------
65
+ <%= color('Environment Variables', :bold) %>
66
+ -----------------------------
67
+
68
+ <%= color 'HOSTS', :bold %>
69
+ Execute the tasks against this comma-separated list of hosts. Effectively, this makes the host(s) part of every roles.
70
+
71
+ <%= color 'HOSTFILTER', :bold %>
72
+ Execute tasks against this comma-separated list of host, but only if the host has the proper role for the task.
73
+
74
+ <%= color 'ROLES', :bold %>
75
+ Execute tasks against this comma-separated list of roles. Hosts which do not have the right roles will be skipped.
@@ -0,0 +1,224 @@
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
+ @option_parser ||= OptionParser.new do |opts|
28
+ opts.banner = "Usage: #{File.basename($0)} [options] action ..."
29
+
30
+ opts.on("-d", "--debug",
31
+ "Prompts before each remote command execution."
32
+ ) { |value| options[:debug] = true }
33
+
34
+ opts.on("-e", "--explain TASK",
35
+ "Displays help (if available) for the task."
36
+ ) { |value| options[:explain] = value }
37
+
38
+ opts.on("-F", "--default-config",
39
+ "Always use default config, even with -f."
40
+ ) { options[:default_config] = true }
41
+
42
+ opts.on("-f", "--file FILE",
43
+ "A recipe file to load. May be given more than once."
44
+ ) { |value| options[:recipes] << value }
45
+
46
+ opts.on("-H", "--long-help", "Explain these options and environment variables.") do
47
+ long_help
48
+ exit
49
+ end
50
+
51
+ opts.on("-h", "--help", "Display this help message.") do
52
+ puts opts
53
+ exit
54
+ end
55
+
56
+ opts.on("-n", "--dry-run",
57
+ "Prints out commands without running them."
58
+ ) { |value| options[:dry_run] = true }
59
+
60
+ opts.on("-p", "--password",
61
+ "Immediately prompt for the password."
62
+ ) { options[:password] = nil }
63
+
64
+ opts.on("-q", "--quiet",
65
+ "Make the output as quiet as possible."
66
+ ) { options[:verbose] = 0 }
67
+
68
+ opts.on("-S", "--set-before NAME=VALUE",
69
+ "Set a variable before the recipes are loaded."
70
+ ) do |pair|
71
+ name, value = pair.split(/=/, 2)
72
+ options[:pre_vars][name.to_sym] = value
73
+ end
74
+
75
+ opts.on("-s", "--set NAME=VALUE",
76
+ "Set a variable after the recipes are loaded."
77
+ ) do |pair|
78
+ name, value = pair.split(/=/, 2)
79
+ options[:vars][name.to_sym] = value
80
+ end
81
+
82
+ opts.on("-T", "--tasks [PATTERN]",
83
+ "List all tasks (matching optional PATTERN) in the loaded recipe files."
84
+ ) do |value|
85
+ options[:tasks] = if value
86
+ value
87
+ else
88
+ true
89
+ end
90
+ options[:verbose] ||= 0
91
+ end
92
+
93
+ opts.on("-t", "--tool",
94
+ "Abbreviates the output of -T for tool integration."
95
+ ) { options[:tool] = true }
96
+
97
+ opts.on("-V", "--version",
98
+ "Display the Capistrano version, and exit."
99
+ ) do
100
+ require 'capistrano/version'
101
+ puts "Capistrano v#{Capistrano::Version::STRING}"
102
+ exit
103
+ end
104
+
105
+ opts.on("-v", "--verbose",
106
+ "Be more verbose. May be given more than once."
107
+ ) do
108
+ options[:verbose] ||= 0
109
+ options[:verbose] += 1
110
+ end
111
+
112
+ opts.on("-X", "--skip-system-config",
113
+ "Don't load the system config file (capistrano.conf)"
114
+ ) { options.delete(:sysconf) }
115
+
116
+ opts.on("-x", "--skip-user-config",
117
+ "Don't load the user config file (.caprc)"
118
+ ) { options.delete(:dotfile) }
119
+ end
120
+ end
121
+
122
+ # If the arguments to the command are empty, this will print the
123
+ # allowed options and exit. Otherwise, it will parse the command
124
+ # line and set up any default options.
125
+ def parse_options! #:nodoc:
126
+ @options = { :recipes => [], :actions => [],
127
+ :vars => {}, :pre_vars => {},
128
+ :sysconf => default_sysconf, :dotfile => default_dotfile }
129
+
130
+ if args.empty?
131
+ warn "Please specify at least one action to execute."
132
+ warn option_parser
133
+ exit
134
+ end
135
+
136
+ option_parser.parse!(args)
137
+
138
+ coerce_variable_types!
139
+
140
+ # if no verbosity has been specified, be verbose
141
+ options[:verbose] = 3 if !options.has_key?(:verbose)
142
+
143
+ look_for_default_recipe_file! if options[:default_config] || options[:recipes].empty?
144
+ extract_environment_variables!
145
+
146
+ options[:actions].concat(args)
147
+
148
+ password = options.has_key?(:password)
149
+ options[:password] = Proc.new { self.class.password_prompt }
150
+ options[:password] = options[:password].call if password
151
+ end
152
+
153
+ # Extracts name=value pairs from the remaining command-line arguments
154
+ # and assigns them as environment variables.
155
+ def extract_environment_variables! #:nodoc:
156
+ args.delete_if do |arg|
157
+ next unless arg.match(/^(\w+)=(.*)$/)
158
+ ENV[$1] = $2
159
+ end
160
+ end
161
+
162
+ # Looks for a default recipe file in the current directory.
163
+ def look_for_default_recipe_file! #:nodoc:
164
+ current = Dir.pwd
165
+
166
+ loop do
167
+ %w(Capfile capfile).each do |file|
168
+ if File.file?(file)
169
+ options[:recipes] << file
170
+ return
171
+ end
172
+ end
173
+
174
+ pwd = Dir.pwd
175
+ Dir.chdir("..")
176
+ break if pwd == Dir.pwd # if changing the directory made no difference, then we're at the top
177
+ end
178
+
179
+ Dir.chdir(current)
180
+ end
181
+
182
+ def default_sysconf #:nodoc:
183
+ File.join(sysconf_directory, "capistrano.conf")
184
+ end
185
+
186
+ def default_dotfile #:nodoc:
187
+ File.join(home_directory, ".caprc")
188
+ end
189
+
190
+ def sysconf_directory #:nodoc:
191
+ # TODO if anyone cares, feel free to submit a patch that uses a more
192
+ # appropriate location for this file in Windows.
193
+ ENV["SystemRoot"] || '/etc'
194
+ end
195
+
196
+ def home_directory #:nodoc:
197
+ ENV["HOME"] ||
198
+ (ENV["HOMEPATH"] && "#{ENV["HOMEDRIVE"]}#{ENV["HOMEPATH"]}") ||
199
+ "/"
200
+ end
201
+
202
+ def coerce_variable_types!
203
+ [:pre_vars, :vars].each do |collection|
204
+ options[collection].keys.each do |key|
205
+ options[collection][key] = coerce_variable(options[collection][key])
206
+ end
207
+ end
208
+ end
209
+
210
+ def coerce_variable(value)
211
+ case value
212
+ when /^"(.*)"$/ then $1
213
+ when /^'(.*)'$/ then $1
214
+ when /^\d+$/ then value.to_i
215
+ when /^\d+\.\d*$/ then value.to_f
216
+ when "true" then true
217
+ when "false" then false
218
+ when "nil" then nil
219
+ else value
220
+ end
221
+ end
222
+ end
223
+ end
224
+ end