engineyard 2.0.0.pre1 → 2.0.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +39 -136
- data/bin/ey_perftools +12 -0
- data/lib/engineyard.rb +0 -2
- data/lib/engineyard/cli.rb +3 -4
- data/lib/engineyard/cli/api.rb +3 -2
- data/lib/engineyard/commands/deploy.rb +0 -0
- data/lib/engineyard/thor.rb +7 -3
- data/lib/engineyard/version.rb +1 -1
- data/spec/engineyard/cli/api_spec.rb +6 -0
- data/spec/ey/deploy_spec.rb +6 -0
- data/spec/ey/ssh_spec.rb +6 -6
- metadata +24 -37
- data/lib/vendor/thor/LICENSE.md +0 -20
- data/lib/vendor/thor/README.md +0 -26
- data/lib/vendor/thor/lib/thor.rb +0 -379
- data/lib/vendor/thor/lib/thor/actions.rb +0 -318
- data/lib/vendor/thor/lib/thor/actions/create_file.rb +0 -105
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +0 -57
- data/lib/vendor/thor/lib/thor/actions/directory.rb +0 -97
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +0 -153
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +0 -308
- data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +0 -109
- data/lib/vendor/thor/lib/thor/base.rb +0 -611
- data/lib/vendor/thor/lib/thor/core_ext/file_binary_read.rb +0 -9
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +0 -75
- data/lib/vendor/thor/lib/thor/core_ext/ordered_hash.rb +0 -100
- data/lib/vendor/thor/lib/thor/error.rb +0 -35
- data/lib/vendor/thor/lib/thor/group.rb +0 -285
- data/lib/vendor/thor/lib/thor/invocation.rb +0 -170
- data/lib/vendor/thor/lib/thor/parser.rb +0 -4
- data/lib/vendor/thor/lib/thor/parser/argument.rb +0 -67
- data/lib/vendor/thor/lib/thor/parser/arguments.rb +0 -165
- data/lib/vendor/thor/lib/thor/parser/option.rb +0 -121
- data/lib/vendor/thor/lib/thor/parser/options.rb +0 -181
- data/lib/vendor/thor/lib/thor/rake_compat.rb +0 -71
- data/lib/vendor/thor/lib/thor/runner.rb +0 -321
- data/lib/vendor/thor/lib/thor/shell.rb +0 -88
- data/lib/vendor/thor/lib/thor/shell/basic.rb +0 -331
- data/lib/vendor/thor/lib/thor/shell/color.rb +0 -108
- data/lib/vendor/thor/lib/thor/shell/html.rb +0 -121
- data/lib/vendor/thor/lib/thor/task.rb +0 -132
- data/lib/vendor/thor/lib/thor/util.rb +0 -248
- data/lib/vendor/thor/lib/thor/version.rb +0 -3
data/lib/vendor/thor/LICENSE.md
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/vendor/thor/README.md
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
Thor
|
2
|
-
====
|
3
|
-
|
4
|
-
Description
|
5
|
-
-----------
|
6
|
-
Thor is a simple and efficient tool for building self-documenting command line
|
7
|
-
utilities. It removes the pain of parsing command line options, writing
|
8
|
-
"USAGE:" banners, and can also be used as an alternative to the [Rake][rake]
|
9
|
-
build tool. The syntax is Rake-like, so it should be familiar to most Rake
|
10
|
-
users.
|
11
|
-
|
12
|
-
[rake]: https://github.com/jimweirich/rake
|
13
|
-
|
14
|
-
Installation
|
15
|
-
------------
|
16
|
-
gem install thor
|
17
|
-
|
18
|
-
Usage and documentation
|
19
|
-
-----------------------
|
20
|
-
Please see [the wiki](https://github.com/wycats/thor/wiki) for basic usage and other documentation on using Thor.
|
21
|
-
|
22
|
-
License
|
23
|
-
-------
|
24
|
-
Released under the MIT License. See the [LICENSE][license] file for further details.
|
25
|
-
|
26
|
-
[license]: https://github.com/wycats/thor/blob/master/LICENSE.md
|
data/lib/vendor/thor/lib/thor.rb
DELETED
@@ -1,379 +0,0 @@
|
|
1
|
-
require 'thor/base'
|
2
|
-
|
3
|
-
class Thor
|
4
|
-
class << self
|
5
|
-
# Sets the default task when thor is executed without an explicit task to be called.
|
6
|
-
#
|
7
|
-
# ==== Parameters
|
8
|
-
# meth<Symbol>:: name of the default task
|
9
|
-
#
|
10
|
-
def default_task(meth=nil)
|
11
|
-
case meth
|
12
|
-
when :none
|
13
|
-
@default_task = 'help'
|
14
|
-
when nil
|
15
|
-
@default_task ||= from_superclass(:default_task, 'help')
|
16
|
-
else
|
17
|
-
@default_task = meth.to_s
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
# Registers another Thor subclass as a command.
|
22
|
-
#
|
23
|
-
# ==== Parameters
|
24
|
-
# klass<Class>:: Thor subclass to register
|
25
|
-
# command<String>:: Subcommand name to use
|
26
|
-
# usage<String>:: Short usage for the subcommand
|
27
|
-
# description<String>:: Description for the subcommand
|
28
|
-
def register(klass, subcommand_name, usage, description, options={})
|
29
|
-
if klass <= Thor::Group
|
30
|
-
desc usage, description, options
|
31
|
-
define_method(subcommand_name) { |*args| invoke(klass, args) }
|
32
|
-
else
|
33
|
-
desc usage, description, options
|
34
|
-
subcommand subcommand_name, klass
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Defines the usage and the description of the next task.
|
39
|
-
#
|
40
|
-
# ==== Parameters
|
41
|
-
# usage<String>
|
42
|
-
# description<String>
|
43
|
-
# options<String>
|
44
|
-
#
|
45
|
-
def desc(usage, description, options={})
|
46
|
-
if options[:for]
|
47
|
-
task = find_and_refresh_task(options[:for])
|
48
|
-
task.usage = usage if usage
|
49
|
-
task.description = description if description
|
50
|
-
else
|
51
|
-
@usage, @desc, @hide = usage, description, options[:hide] || false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Defines the long description of the next task.
|
56
|
-
#
|
57
|
-
# ==== Parameters
|
58
|
-
# long description<String>
|
59
|
-
#
|
60
|
-
def long_desc(long_description, options={})
|
61
|
-
if options[:for]
|
62
|
-
task = find_and_refresh_task(options[:for])
|
63
|
-
task.long_description = long_description if long_description
|
64
|
-
else
|
65
|
-
@long_desc = long_description
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Maps an input to a task. If you define:
|
70
|
-
#
|
71
|
-
# map "-T" => "list"
|
72
|
-
#
|
73
|
-
# Running:
|
74
|
-
#
|
75
|
-
# thor -T
|
76
|
-
#
|
77
|
-
# Will invoke the list task.
|
78
|
-
#
|
79
|
-
# ==== Parameters
|
80
|
-
# Hash[String|Array => Symbol]:: Maps the string or the strings in the array to the given task.
|
81
|
-
#
|
82
|
-
def map(mappings=nil)
|
83
|
-
@map ||= from_superclass(:map, {})
|
84
|
-
|
85
|
-
if mappings
|
86
|
-
mappings.each do |key, value|
|
87
|
-
if key.respond_to?(:each)
|
88
|
-
key.each {|subkey| @map[subkey] = value}
|
89
|
-
else
|
90
|
-
@map[key] = value
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
@map
|
96
|
-
end
|
97
|
-
|
98
|
-
# Declares the options for the next task to be declared.
|
99
|
-
#
|
100
|
-
# ==== Parameters
|
101
|
-
# Hash[Symbol => Object]:: The hash key is the name of the option and the value
|
102
|
-
# is the type of the option. Can be :string, :array, :hash, :boolean, :numeric
|
103
|
-
# or :required (string). If you give a value, the type of the value is used.
|
104
|
-
#
|
105
|
-
def method_options(options=nil)
|
106
|
-
@method_options ||= {}
|
107
|
-
build_options(options, @method_options) if options
|
108
|
-
@method_options
|
109
|
-
end
|
110
|
-
|
111
|
-
alias options method_options
|
112
|
-
|
113
|
-
# Adds an option to the set of method options. If :for is given as option,
|
114
|
-
# it allows you to change the options from a previous defined task.
|
115
|
-
#
|
116
|
-
# def previous_task
|
117
|
-
# # magic
|
118
|
-
# end
|
119
|
-
#
|
120
|
-
# method_option :foo => :bar, :for => :previous_task
|
121
|
-
#
|
122
|
-
# def next_task
|
123
|
-
# # magic
|
124
|
-
# end
|
125
|
-
#
|
126
|
-
# ==== Parameters
|
127
|
-
# name<Symbol>:: The name of the argument.
|
128
|
-
# options<Hash>:: Described below.
|
129
|
-
#
|
130
|
-
# ==== Options
|
131
|
-
# :desc - Description for the argument.
|
132
|
-
# :required - If the argument is required or not.
|
133
|
-
# :default - Default value for this argument. It cannot be required and have default values.
|
134
|
-
# :aliases - Aliases for this option.
|
135
|
-
# :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
|
136
|
-
# :banner - String to show on usage notes.
|
137
|
-
# :hide - If you want to hide this option from the help.
|
138
|
-
#
|
139
|
-
def method_option(name, options={})
|
140
|
-
scope = if options[:for]
|
141
|
-
find_and_refresh_task(options[:for]).options
|
142
|
-
else
|
143
|
-
method_options
|
144
|
-
end
|
145
|
-
|
146
|
-
build_option(name, options, scope)
|
147
|
-
end
|
148
|
-
|
149
|
-
alias option method_option
|
150
|
-
|
151
|
-
# Prints help information for the given task.
|
152
|
-
#
|
153
|
-
# ==== Parameters
|
154
|
-
# shell<Thor::Shell>
|
155
|
-
# task_name<String>
|
156
|
-
#
|
157
|
-
def task_help(shell, task_name)
|
158
|
-
meth = normalize_task_name(task_name)
|
159
|
-
task = all_tasks[meth]
|
160
|
-
handle_no_task_error(meth) unless task
|
161
|
-
|
162
|
-
shell.say "Usage:"
|
163
|
-
shell.say " #{banner(task)}"
|
164
|
-
shell.say
|
165
|
-
class_options_help(shell, nil => task.options.map { |_, o| o })
|
166
|
-
if task.long_description
|
167
|
-
shell.say "Description:"
|
168
|
-
shell.print_wrapped(task.long_description, :indent => 2)
|
169
|
-
else
|
170
|
-
shell.say task.description
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
# Prints help information for this class.
|
175
|
-
#
|
176
|
-
# ==== Parameters
|
177
|
-
# shell<Thor::Shell>
|
178
|
-
#
|
179
|
-
def help(shell, subcommand = false)
|
180
|
-
list = printable_tasks(true, subcommand)
|
181
|
-
Thor::Util.thor_classes_in(self).each do |klass|
|
182
|
-
list += klass.printable_tasks(false)
|
183
|
-
end
|
184
|
-
list.sort!{ |a,b| a[0] <=> b[0] }
|
185
|
-
|
186
|
-
shell.say "Tasks:"
|
187
|
-
shell.print_table(list, :indent => 2, :truncate => true)
|
188
|
-
shell.say
|
189
|
-
class_options_help(shell)
|
190
|
-
end
|
191
|
-
|
192
|
-
# Returns tasks ready to be printed.
|
193
|
-
def printable_tasks(all = true, subcommand = false)
|
194
|
-
(all ? all_tasks : tasks).map do |_, task|
|
195
|
-
next if task.hidden?
|
196
|
-
item = []
|
197
|
-
item << banner(task, false, subcommand)
|
198
|
-
item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "")
|
199
|
-
item
|
200
|
-
end.compact
|
201
|
-
end
|
202
|
-
|
203
|
-
def subcommands
|
204
|
-
@subcommands ||= from_superclass(:subcommands, [])
|
205
|
-
end
|
206
|
-
|
207
|
-
def subcommand(subcommand, subcommand_class)
|
208
|
-
self.subcommands << subcommand.to_s
|
209
|
-
subcommand_class.subcommand_help subcommand
|
210
|
-
|
211
|
-
define_method(subcommand) do |*args|
|
212
|
-
args, opts = Thor::Arguments.split(args)
|
213
|
-
invoke subcommand_class, args, opts
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
# Extend check unknown options to accept a hash of conditions.
|
218
|
-
#
|
219
|
-
# === Parameters
|
220
|
-
# options<Hash>: A hash containing :only and/or :except keys
|
221
|
-
def check_unknown_options!(options={})
|
222
|
-
@check_unknown_options ||= Hash.new
|
223
|
-
options.each do |key, value|
|
224
|
-
if value
|
225
|
-
@check_unknown_options[key] = Array(value)
|
226
|
-
else
|
227
|
-
@check_unknown_options.delete(key)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
@check_unknown_options
|
231
|
-
end
|
232
|
-
|
233
|
-
# Overwrite check_unknown_options? to take subcommands and options into account.
|
234
|
-
def check_unknown_options?(config) #:nodoc:
|
235
|
-
options = check_unknown_options
|
236
|
-
return false unless options
|
237
|
-
|
238
|
-
task = config[:current_task]
|
239
|
-
return true unless task
|
240
|
-
|
241
|
-
name = task.name
|
242
|
-
|
243
|
-
if subcommands.include?(name)
|
244
|
-
false
|
245
|
-
elsif options[:except]
|
246
|
-
!options[:except].include?(name.to_sym)
|
247
|
-
elsif options[:only]
|
248
|
-
options[:only].include?(name.to_sym)
|
249
|
-
else
|
250
|
-
true
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
protected
|
255
|
-
|
256
|
-
# The method responsible for dispatching given the args.
|
257
|
-
def dispatch(meth, given_args, given_opts, config) #:nodoc:
|
258
|
-
meth ||= retrieve_task_name(given_args)
|
259
|
-
task = all_tasks[normalize_task_name(meth)]
|
260
|
-
|
261
|
-
if task
|
262
|
-
args, opts = Thor::Options.split(given_args)
|
263
|
-
else
|
264
|
-
args, opts = given_args, nil
|
265
|
-
task = Thor::DynamicTask.new(meth)
|
266
|
-
end
|
267
|
-
|
268
|
-
opts = given_opts || opts || []
|
269
|
-
config.merge!(:current_task => task, :task_options => task.options)
|
270
|
-
|
271
|
-
instance = new(args, opts, config)
|
272
|
-
yield instance if block_given?
|
273
|
-
args = instance.args
|
274
|
-
trailing = args[Range.new(arguments.size, -1)]
|
275
|
-
instance.invoke_task(task, trailing || [])
|
276
|
-
end
|
277
|
-
|
278
|
-
# The banner for this class. You can customize it if you are invoking the
|
279
|
-
# thor class by another ways which is not the Thor::Runner. It receives
|
280
|
-
# the task that is going to be invoked and a boolean which indicates if
|
281
|
-
# the namespace should be displayed as arguments.
|
282
|
-
#
|
283
|
-
def banner(task, namespace = nil, subcommand = false)
|
284
|
-
"#{basename} #{task.formatted_usage(self, $thor_runner, subcommand)}"
|
285
|
-
end
|
286
|
-
|
287
|
-
def baseclass #:nodoc:
|
288
|
-
Thor
|
289
|
-
end
|
290
|
-
|
291
|
-
def create_task(meth) #:nodoc:
|
292
|
-
if @usage && @desc
|
293
|
-
base_class = @hide ? Thor::HiddenTask : Thor::Task
|
294
|
-
tasks[meth] = base_class.new(meth, @desc, @long_desc, @usage, method_options)
|
295
|
-
@usage, @desc, @long_desc, @method_options, @hide = nil
|
296
|
-
true
|
297
|
-
elsif self.all_tasks[meth] || meth == "method_missing"
|
298
|
-
true
|
299
|
-
else
|
300
|
-
puts "[WARNING] Attempted to create task #{meth.inspect} without usage or description. " <<
|
301
|
-
"Call desc if you want this method to be available as task or declare it inside a " <<
|
302
|
-
"no_tasks{} block. Invoked from #{caller[1].inspect}."
|
303
|
-
false
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
def initialize_added #:nodoc:
|
308
|
-
class_options.merge!(method_options)
|
309
|
-
@method_options = nil
|
310
|
-
end
|
311
|
-
|
312
|
-
# Retrieve the task name from given args.
|
313
|
-
def retrieve_task_name(args) #:nodoc:
|
314
|
-
meth = args.first.to_s unless args.empty?
|
315
|
-
if meth && (map[meth] || meth !~ /^\-/)
|
316
|
-
args.shift
|
317
|
-
else
|
318
|
-
nil
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
# receives a (possibly nil) task name and returns a name that is in
|
323
|
-
# the tasks hash. In addition to normalizing aliases, this logic
|
324
|
-
# will determine if a shortened command is an unambiguous prefix of
|
325
|
-
# a task or alias.
|
326
|
-
#
|
327
|
-
# +normalize_task_name+ also converts names like +animal-prison+
|
328
|
-
# into +animal_prison+.
|
329
|
-
def normalize_task_name(meth) #:nodoc:
|
330
|
-
return default_task.to_s.gsub('-', '_') unless meth
|
331
|
-
|
332
|
-
possibilities = find_task_possibilities(meth)
|
333
|
-
if possibilities.size > 1
|
334
|
-
raise ArgumentError, "Ambiguous task #{meth} matches [#{possibilities.join(', ')}]"
|
335
|
-
elsif possibilities.size < 1
|
336
|
-
meth = meth || default_task
|
337
|
-
elsif map[meth]
|
338
|
-
meth = map[meth]
|
339
|
-
else
|
340
|
-
meth = possibilities.first
|
341
|
-
end
|
342
|
-
|
343
|
-
meth.to_s.gsub('-','_') # treat foo-bar as foo_bar
|
344
|
-
end
|
345
|
-
|
346
|
-
# this is the logic that takes the task name passed in by the user
|
347
|
-
# and determines whether it is an unambiguous prefix of a task or
|
348
|
-
# alias name.
|
349
|
-
def find_task_possibilities(meth)
|
350
|
-
len = meth.to_s.length
|
351
|
-
possibilities = all_tasks.merge(map).keys.select { |n| meth == n[0, len] }.sort
|
352
|
-
unique_possibilities = possibilities.map { |k| map[k] || k }.uniq
|
353
|
-
|
354
|
-
if possibilities.include?(meth)
|
355
|
-
[meth]
|
356
|
-
elsif unique_possibilities.size == 1
|
357
|
-
unique_possibilities
|
358
|
-
else
|
359
|
-
possibilities
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
def subcommand_help(cmd)
|
364
|
-
desc "help [COMMAND]", "Describe subcommands or one specific subcommand"
|
365
|
-
class_eval <<-RUBY
|
366
|
-
def help(task = nil, subcommand = true); super; end
|
367
|
-
RUBY
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
include Thor::Base
|
372
|
-
|
373
|
-
map HELP_MAPPINGS => :help
|
374
|
-
|
375
|
-
desc "help [TASK]", "Describe available tasks or one specific task"
|
376
|
-
def help(task = nil, subcommand = false)
|
377
|
-
task ? self.class.task_help(shell, task) : self.class.help(shell, subcommand)
|
378
|
-
end
|
379
|
-
end
|
@@ -1,318 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'uri'
|
3
|
-
require 'thor/core_ext/file_binary_read'
|
4
|
-
require 'thor/actions/create_file'
|
5
|
-
require 'thor/actions/create_link'
|
6
|
-
require 'thor/actions/directory'
|
7
|
-
require 'thor/actions/empty_directory'
|
8
|
-
require 'thor/actions/file_manipulation'
|
9
|
-
require 'thor/actions/inject_into_file'
|
10
|
-
|
11
|
-
class Thor
|
12
|
-
module Actions
|
13
|
-
attr_accessor :behavior
|
14
|
-
|
15
|
-
def self.included(base) #:nodoc:
|
16
|
-
base.extend ClassMethods
|
17
|
-
end
|
18
|
-
|
19
|
-
module ClassMethods
|
20
|
-
# Hold source paths for one Thor instance. source_paths_for_search is the
|
21
|
-
# method responsible to gather source_paths from this current class,
|
22
|
-
# inherited paths and the source root.
|
23
|
-
#
|
24
|
-
def source_paths
|
25
|
-
@_source_paths ||= []
|
26
|
-
end
|
27
|
-
|
28
|
-
# Stores and return the source root for this class
|
29
|
-
def source_root(path=nil)
|
30
|
-
@_source_root = path if path
|
31
|
-
@_source_root
|
32
|
-
end
|
33
|
-
|
34
|
-
# Returns the source paths in the following order:
|
35
|
-
#
|
36
|
-
# 1) This class source paths
|
37
|
-
# 2) Source root
|
38
|
-
# 3) Parents source paths
|
39
|
-
#
|
40
|
-
def source_paths_for_search
|
41
|
-
paths = []
|
42
|
-
paths += self.source_paths
|
43
|
-
paths << self.source_root if self.source_root
|
44
|
-
paths += from_superclass(:source_paths, [])
|
45
|
-
paths
|
46
|
-
end
|
47
|
-
|
48
|
-
# Add runtime options that help actions execution.
|
49
|
-
#
|
50
|
-
def add_runtime_options!
|
51
|
-
class_option :force, :type => :boolean, :aliases => "-f", :group => :runtime,
|
52
|
-
:desc => "Overwrite files that already exist"
|
53
|
-
|
54
|
-
class_option :pretend, :type => :boolean, :aliases => "-p", :group => :runtime,
|
55
|
-
:desc => "Run but do not make any changes"
|
56
|
-
|
57
|
-
class_option :quiet, :type => :boolean, :aliases => "-q", :group => :runtime,
|
58
|
-
:desc => "Supress status output"
|
59
|
-
|
60
|
-
class_option :skip, :type => :boolean, :aliases => "-s", :group => :runtime,
|
61
|
-
:desc => "Skip files that already exist"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Extends initializer to add more configuration options.
|
66
|
-
#
|
67
|
-
# ==== Configuration
|
68
|
-
# behavior<Symbol>:: The actions default behavior. Can be :invoke or :revoke.
|
69
|
-
# It also accepts :force, :skip and :pretend to set the behavior
|
70
|
-
# and the respective option.
|
71
|
-
#
|
72
|
-
# destination_root<String>:: The root directory needed for some actions.
|
73
|
-
#
|
74
|
-
def initialize(args=[], options={}, config={})
|
75
|
-
self.behavior = case config[:behavior].to_s
|
76
|
-
when "force", "skip"
|
77
|
-
_cleanup_options_and_set(options, config[:behavior])
|
78
|
-
:invoke
|
79
|
-
when "revoke"
|
80
|
-
:revoke
|
81
|
-
else
|
82
|
-
:invoke
|
83
|
-
end
|
84
|
-
|
85
|
-
super
|
86
|
-
self.destination_root = config[:destination_root]
|
87
|
-
end
|
88
|
-
|
89
|
-
# Wraps an action object and call it accordingly to the thor class behavior.
|
90
|
-
#
|
91
|
-
def action(instance) #:nodoc:
|
92
|
-
if behavior == :revoke
|
93
|
-
instance.revoke!
|
94
|
-
else
|
95
|
-
instance.invoke!
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Returns the root for this thor class (also aliased as destination root).
|
100
|
-
#
|
101
|
-
def destination_root
|
102
|
-
@destination_stack.last
|
103
|
-
end
|
104
|
-
|
105
|
-
# Sets the root for this thor class. Relatives path are added to the
|
106
|
-
# directory where the script was invoked and expanded.
|
107
|
-
#
|
108
|
-
def destination_root=(root)
|
109
|
-
@destination_stack ||= []
|
110
|
-
@destination_stack[0] = File.expand_path(root || '')
|
111
|
-
end
|
112
|
-
|
113
|
-
# Returns the given path relative to the absolute root (ie, root where
|
114
|
-
# the script started).
|
115
|
-
#
|
116
|
-
def relative_to_original_destination_root(path, remove_dot=true)
|
117
|
-
if path =~ /^#{@destination_stack[0]}/
|
118
|
-
path = path.gsub(@destination_stack[0], '.')
|
119
|
-
path = remove_dot ? (path[2..-1] || '') : path
|
120
|
-
end
|
121
|
-
|
122
|
-
path
|
123
|
-
end
|
124
|
-
|
125
|
-
# Holds source paths in instance so they can be manipulated.
|
126
|
-
#
|
127
|
-
def source_paths
|
128
|
-
@source_paths ||= self.class.source_paths_for_search
|
129
|
-
end
|
130
|
-
|
131
|
-
# Receives a file or directory and search for it in the source paths.
|
132
|
-
#
|
133
|
-
def find_in_source_paths(file)
|
134
|
-
relative_root = relative_to_original_destination_root(destination_root, false)
|
135
|
-
|
136
|
-
source_paths.each do |source|
|
137
|
-
source_file = File.expand_path(file, File.join(source, relative_root))
|
138
|
-
return source_file if File.exists?(source_file)
|
139
|
-
end
|
140
|
-
|
141
|
-
message = "Could not find #{file.inspect} in any of your source paths. "
|
142
|
-
|
143
|
-
unless self.class.source_root
|
144
|
-
message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. "
|
145
|
-
end
|
146
|
-
|
147
|
-
if source_paths.empty?
|
148
|
-
message << "Currently you have no source paths."
|
149
|
-
else
|
150
|
-
message << "Your current source paths are: \n#{source_paths.join("\n")}"
|
151
|
-
end
|
152
|
-
|
153
|
-
raise Error, message
|
154
|
-
end
|
155
|
-
|
156
|
-
# Do something in the root or on a provided subfolder. If a relative path
|
157
|
-
# is given it's referenced from the current root. The full path is yielded
|
158
|
-
# to the block you provide. The path is set back to the previous path when
|
159
|
-
# the method exits.
|
160
|
-
#
|
161
|
-
# ==== Parameters
|
162
|
-
# dir<String>:: the directory to move to.
|
163
|
-
# config<Hash>:: give :verbose => true to log and use padding.
|
164
|
-
#
|
165
|
-
def inside(dir='', config={}, &block)
|
166
|
-
verbose = config.fetch(:verbose, false)
|
167
|
-
pretend = options[:pretend]
|
168
|
-
|
169
|
-
say_status :inside, dir, verbose
|
170
|
-
shell.padding += 1 if verbose
|
171
|
-
@destination_stack.push File.expand_path(dir, destination_root)
|
172
|
-
|
173
|
-
# If the directory doesnt exist and we're not pretending
|
174
|
-
if !File.exist?(destination_root) && !pretend
|
175
|
-
FileUtils.mkdir_p(destination_root)
|
176
|
-
end
|
177
|
-
|
178
|
-
if pretend
|
179
|
-
# In pretend mode, just yield down to the block
|
180
|
-
block.arity == 1 ? yield(destination_root) : yield
|
181
|
-
else
|
182
|
-
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
183
|
-
end
|
184
|
-
|
185
|
-
@destination_stack.pop
|
186
|
-
shell.padding -= 1 if verbose
|
187
|
-
end
|
188
|
-
|
189
|
-
# Goes to the root and execute the given block.
|
190
|
-
#
|
191
|
-
def in_root
|
192
|
-
inside(@destination_stack.first) { yield }
|
193
|
-
end
|
194
|
-
|
195
|
-
# Loads an external file and execute it in the instance binding.
|
196
|
-
#
|
197
|
-
# ==== Parameters
|
198
|
-
# path<String>:: The path to the file to execute. Can be a web address or
|
199
|
-
# a relative path from the source root.
|
200
|
-
#
|
201
|
-
# ==== Examples
|
202
|
-
#
|
203
|
-
# apply "http://gist.github.com/103208"
|
204
|
-
#
|
205
|
-
# apply "recipes/jquery.rb"
|
206
|
-
#
|
207
|
-
def apply(path, config={})
|
208
|
-
verbose = config.fetch(:verbose, true)
|
209
|
-
is_uri = path =~ /^https?\:\/\//
|
210
|
-
path = find_in_source_paths(path) unless is_uri
|
211
|
-
|
212
|
-
say_status :apply, path, verbose
|
213
|
-
shell.padding += 1 if verbose
|
214
|
-
|
215
|
-
if is_uri
|
216
|
-
contents = open(path, "Accept" => "application/x-thor-template") {|io| io.read }
|
217
|
-
else
|
218
|
-
contents = open(path) {|io| io.read }
|
219
|
-
end
|
220
|
-
|
221
|
-
instance_eval(contents, path)
|
222
|
-
shell.padding -= 1 if verbose
|
223
|
-
end
|
224
|
-
|
225
|
-
# Executes a command returning the contents of the command.
|
226
|
-
#
|
227
|
-
# ==== Parameters
|
228
|
-
# command<String>:: the command to be executed.
|
229
|
-
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
|
230
|
-
# to append an executable to command executation.
|
231
|
-
#
|
232
|
-
# ==== Example
|
233
|
-
#
|
234
|
-
# inside('vendor') do
|
235
|
-
# run('ln -s ~/edge rails')
|
236
|
-
# end
|
237
|
-
#
|
238
|
-
def run(command, config={})
|
239
|
-
return unless behavior == :invoke
|
240
|
-
|
241
|
-
destination = relative_to_original_destination_root(destination_root, false)
|
242
|
-
desc = "#{command} from #{destination.inspect}"
|
243
|
-
|
244
|
-
if config[:with]
|
245
|
-
desc = "#{File.basename(config[:with].to_s)} #{desc}"
|
246
|
-
command = "#{config[:with]} #{command}"
|
247
|
-
end
|
248
|
-
|
249
|
-
say_status :run, desc, config.fetch(:verbose, true)
|
250
|
-
|
251
|
-
unless options[:pretend]
|
252
|
-
config[:capture] ? `#{command}` : system("#{command}")
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
# Executes a ruby script (taking into account WIN32 platform quirks).
|
257
|
-
#
|
258
|
-
# ==== Parameters
|
259
|
-
# command<String>:: the command to be executed.
|
260
|
-
# config<Hash>:: give :verbose => false to not log the status.
|
261
|
-
#
|
262
|
-
def run_ruby_script(command, config={})
|
263
|
-
return unless behavior == :invoke
|
264
|
-
run command, config.merge(:with => Thor::Util.ruby_command)
|
265
|
-
end
|
266
|
-
|
267
|
-
# Run a thor command. A hash of options can be given and it's converted to
|
268
|
-
# switches.
|
269
|
-
#
|
270
|
-
# ==== Parameters
|
271
|
-
# task<String>:: the task to be invoked
|
272
|
-
# args<Array>:: arguments to the task
|
273
|
-
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
|
274
|
-
# Other options are given as parameter to Thor.
|
275
|
-
#
|
276
|
-
#
|
277
|
-
# ==== Examples
|
278
|
-
#
|
279
|
-
# thor :install, "http://gist.github.com/103208"
|
280
|
-
# #=> thor install http://gist.github.com/103208
|
281
|
-
#
|
282
|
-
# thor :list, :all => true, :substring => 'rails'
|
283
|
-
# #=> thor list --all --substring=rails
|
284
|
-
#
|
285
|
-
def thor(task, *args)
|
286
|
-
config = args.last.is_a?(Hash) ? args.pop : {}
|
287
|
-
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
288
|
-
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
289
|
-
capture = config.key?(:capture) ? config.delete(:capture) : false
|
290
|
-
|
291
|
-
args.unshift task
|
292
|
-
args.push Thor::Options.to_switches(config)
|
293
|
-
command = args.join(' ').strip
|
294
|
-
|
295
|
-
run command, :with => :thor, :verbose => verbose, :pretend => pretend, :capture => capture
|
296
|
-
end
|
297
|
-
|
298
|
-
protected
|
299
|
-
|
300
|
-
# Allow current root to be shared between invocations.
|
301
|
-
#
|
302
|
-
def _shared_configuration #:nodoc:
|
303
|
-
super.merge!(:destination_root => self.destination_root)
|
304
|
-
end
|
305
|
-
|
306
|
-
def _cleanup_options_and_set(options, key) #:nodoc:
|
307
|
-
case options
|
308
|
-
when Array
|
309
|
-
%w(--force -f --skip -s).each { |i| options.delete(i) }
|
310
|
-
options << "--#{key}"
|
311
|
-
when Hash
|
312
|
-
[:force, :skip, "force", "skip"].each { |i| options.delete(i) }
|
313
|
-
options.merge!(key => true)
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
end
|
318
|
-
end
|