minmb-capistrano 2.15.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/.gitignore +10 -0
  2. data/.travis.yml +7 -0
  3. data/CHANGELOG +1170 -0
  4. data/Gemfile +13 -0
  5. data/README.md +94 -0
  6. data/Rakefile +11 -0
  7. data/bin/cap +4 -0
  8. data/bin/capify +92 -0
  9. data/capistrano.gemspec +40 -0
  10. data/lib/capistrano.rb +5 -0
  11. data/lib/capistrano/callback.rb +45 -0
  12. data/lib/capistrano/cli.rb +47 -0
  13. data/lib/capistrano/cli/execute.rb +85 -0
  14. data/lib/capistrano/cli/help.rb +125 -0
  15. data/lib/capistrano/cli/help.txt +81 -0
  16. data/lib/capistrano/cli/options.rb +243 -0
  17. data/lib/capistrano/cli/ui.rb +40 -0
  18. data/lib/capistrano/command.rb +303 -0
  19. data/lib/capistrano/configuration.rb +57 -0
  20. data/lib/capistrano/configuration/actions/file_transfer.rb +50 -0
  21. data/lib/capistrano/configuration/actions/inspect.rb +46 -0
  22. data/lib/capistrano/configuration/actions/invocation.rb +329 -0
  23. data/lib/capistrano/configuration/alias_task.rb +26 -0
  24. data/lib/capistrano/configuration/callbacks.rb +147 -0
  25. data/lib/capistrano/configuration/connections.rb +237 -0
  26. data/lib/capistrano/configuration/execution.rb +142 -0
  27. data/lib/capistrano/configuration/loading.rb +205 -0
  28. data/lib/capistrano/configuration/log_formatters.rb +75 -0
  29. data/lib/capistrano/configuration/namespaces.rb +223 -0
  30. data/lib/capistrano/configuration/roles.rb +77 -0
  31. data/lib/capistrano/configuration/servers.rb +116 -0
  32. data/lib/capistrano/configuration/variables.rb +127 -0
  33. data/lib/capistrano/errors.rb +19 -0
  34. data/lib/capistrano/ext/multistage.rb +64 -0
  35. data/lib/capistrano/ext/string.rb +5 -0
  36. data/lib/capistrano/extensions.rb +57 -0
  37. data/lib/capistrano/fix_rake_deprecated_dsl.rb +8 -0
  38. data/lib/capistrano/logger.rb +166 -0
  39. data/lib/capistrano/processable.rb +57 -0
  40. data/lib/capistrano/recipes/compat.rb +32 -0
  41. data/lib/capistrano/recipes/deploy.rb +625 -0
  42. data/lib/capistrano/recipes/deploy/assets.rb +201 -0
  43. data/lib/capistrano/recipes/deploy/dependencies.rb +44 -0
  44. data/lib/capistrano/recipes/deploy/local_dependency.rb +54 -0
  45. data/lib/capistrano/recipes/deploy/remote_dependency.rb +117 -0
  46. data/lib/capistrano/recipes/deploy/scm.rb +19 -0
  47. data/lib/capistrano/recipes/deploy/scm/accurev.rb +169 -0
  48. data/lib/capistrano/recipes/deploy/scm/base.rb +200 -0
  49. data/lib/capistrano/recipes/deploy/scm/bzr.rb +86 -0
  50. data/lib/capistrano/recipes/deploy/scm/cvs.rb +153 -0
  51. data/lib/capistrano/recipes/deploy/scm/darcs.rb +96 -0
  52. data/lib/capistrano/recipes/deploy/scm/git.rb +293 -0
  53. data/lib/capistrano/recipes/deploy/scm/mercurial.rb +137 -0
  54. data/lib/capistrano/recipes/deploy/scm/none.rb +55 -0
  55. data/lib/capistrano/recipes/deploy/scm/perforce.rb +152 -0
  56. data/lib/capistrano/recipes/deploy/scm/subversion.rb +121 -0
  57. data/lib/capistrano/recipes/deploy/strategy.rb +19 -0
  58. data/lib/capistrano/recipes/deploy/strategy/base.rb +92 -0
  59. data/lib/capistrano/recipes/deploy/strategy/checkout.rb +20 -0
  60. data/lib/capistrano/recipes/deploy/strategy/copy.rb +338 -0
  61. data/lib/capistrano/recipes/deploy/strategy/export.rb +20 -0
  62. data/lib/capistrano/recipes/deploy/strategy/remote.rb +52 -0
  63. data/lib/capistrano/recipes/deploy/strategy/remote_cache.rb +57 -0
  64. data/lib/capistrano/recipes/deploy/strategy/unshared_remote_cache.rb +21 -0
  65. data/lib/capistrano/recipes/standard.rb +37 -0
  66. data/lib/capistrano/recipes/templates/maintenance.rhtml +53 -0
  67. data/lib/capistrano/role.rb +102 -0
  68. data/lib/capistrano/server_definition.rb +56 -0
  69. data/lib/capistrano/shell.rb +265 -0
  70. data/lib/capistrano/ssh.rb +95 -0
  71. data/lib/capistrano/task_definition.rb +77 -0
  72. data/lib/capistrano/transfer.rb +218 -0
  73. data/lib/capistrano/version.rb +11 -0
  74. data/test/cli/execute_test.rb +132 -0
  75. data/test/cli/help_test.rb +165 -0
  76. data/test/cli/options_test.rb +329 -0
  77. data/test/cli/ui_test.rb +28 -0
  78. data/test/cli_test.rb +17 -0
  79. data/test/command_test.rb +322 -0
  80. data/test/configuration/actions/file_transfer_test.rb +61 -0
  81. data/test/configuration/actions/inspect_test.rb +76 -0
  82. data/test/configuration/actions/invocation_test.rb +288 -0
  83. data/test/configuration/alias_task_test.rb +118 -0
  84. data/test/configuration/callbacks_test.rb +201 -0
  85. data/test/configuration/connections_test.rb +439 -0
  86. data/test/configuration/execution_test.rb +175 -0
  87. data/test/configuration/loading_test.rb +148 -0
  88. data/test/configuration/namespace_dsl_test.rb +332 -0
  89. data/test/configuration/roles_test.rb +157 -0
  90. data/test/configuration/servers_test.rb +183 -0
  91. data/test/configuration/variables_test.rb +190 -0
  92. data/test/configuration_test.rb +77 -0
  93. data/test/deploy/local_dependency_test.rb +76 -0
  94. data/test/deploy/remote_dependency_test.rb +146 -0
  95. data/test/deploy/scm/accurev_test.rb +23 -0
  96. data/test/deploy/scm/base_test.rb +55 -0
  97. data/test/deploy/scm/bzr_test.rb +51 -0
  98. data/test/deploy/scm/darcs_test.rb +37 -0
  99. data/test/deploy/scm/git_test.rb +221 -0
  100. data/test/deploy/scm/mercurial_test.rb +134 -0
  101. data/test/deploy/scm/none_test.rb +35 -0
  102. data/test/deploy/scm/perforce_test.rb +23 -0
  103. data/test/deploy/scm/subversion_test.rb +40 -0
  104. data/test/deploy/strategy/copy_test.rb +360 -0
  105. data/test/extensions_test.rb +69 -0
  106. data/test/fixtures/cli_integration.rb +5 -0
  107. data/test/fixtures/config.rb +5 -0
  108. data/test/fixtures/custom.rb +3 -0
  109. data/test/logger_formatting_test.rb +149 -0
  110. data/test/logger_test.rb +134 -0
  111. data/test/recipes_test.rb +25 -0
  112. data/test/role_test.rb +11 -0
  113. data/test/server_definition_test.rb +121 -0
  114. data/test/shell_test.rb +96 -0
  115. data/test/ssh_test.rb +113 -0
  116. data/test/task_definition_test.rb +117 -0
  117. data/test/transfer_test.rb +168 -0
  118. data/test/utils.rb +37 -0
  119. metadata +316 -0
@@ -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? )
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,81 @@
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.
@@ -0,0 +1,243 @@
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