engineyard 2.1.1 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/engineyard/version.rb +2 -2
- data/lib/vendor/thor/README.md +10 -3
- data/lib/vendor/thor/lib/thor.rb +247 -153
- data/lib/vendor/thor/lib/thor/actions.rb +18 -18
- data/lib/vendor/thor/lib/thor/actions/create_link.rb +3 -0
- data/lib/vendor/thor/lib/thor/actions/directory.rb +31 -10
- data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +3 -19
- data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +9 -3
- data/lib/vendor/thor/lib/thor/base.rb +99 -88
- data/lib/vendor/thor/lib/thor/{task.rb → command.rb} +19 -15
- data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +5 -0
- data/lib/vendor/thor/lib/thor/core_ext/io_binary_read.rb +12 -0
- data/lib/vendor/thor/lib/thor/error.rb +4 -11
- data/lib/vendor/thor/lib/thor/group.rb +35 -38
- data/lib/vendor/thor/lib/thor/invocation.rb +28 -26
- data/lib/vendor/thor/lib/thor/parser/options.rb +66 -26
- data/lib/vendor/thor/lib/thor/rake_compat.rb +3 -2
- data/lib/vendor/thor/lib/thor/runner.rb +21 -20
- data/lib/vendor/thor/lib/thor/shell/basic.rb +21 -17
- data/lib/vendor/thor/lib/thor/shell/color.rb +13 -9
- data/lib/vendor/thor/lib/thor/shell/html.rb +13 -9
- data/lib/vendor/thor/lib/thor/util.rb +214 -210
- data/lib/vendor/thor/lib/thor/version.rb +1 -1
- data/lib/vendor/thor/thor.gemspec +22 -24
- metadata +8 -9
- data/lib/vendor/thor/lib/thor/core_ext/dir_escape.rb +0 -0
- data/lib/vendor/thor/lib/thor/core_ext/file_binary_read.rb +0 -9
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'uri'
|
3
|
-
require 'thor/core_ext/
|
3
|
+
require 'thor/core_ext/io_binary_read'
|
4
4
|
require 'thor/actions/create_file'
|
5
5
|
require 'thor/actions/create_link'
|
6
6
|
require 'thor/actions/directory'
|
@@ -73,13 +73,13 @@ class Thor
|
|
73
73
|
#
|
74
74
|
def initialize(args=[], options={}, config={})
|
75
75
|
self.behavior = case config[:behavior].to_s
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
76
|
+
when "force", "skip"
|
77
|
+
_cleanup_options_and_set(options, config[:behavior])
|
78
|
+
:invoke
|
79
|
+
when "revoke"
|
80
|
+
:revoke
|
81
|
+
else
|
82
|
+
:invoke
|
83
83
|
end
|
84
84
|
|
85
85
|
super
|
@@ -268,8 +268,8 @@ class Thor
|
|
268
268
|
# switches.
|
269
269
|
#
|
270
270
|
# ==== Parameters
|
271
|
-
#
|
272
|
-
# args<Array>:: arguments to the
|
271
|
+
# command<String>:: the command to be invoked
|
272
|
+
# args<Array>:: arguments to the command
|
273
273
|
# config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output.
|
274
274
|
# Other options are given as parameter to Thor.
|
275
275
|
#
|
@@ -282,13 +282,13 @@ class Thor
|
|
282
282
|
# thor :list, :all => true, :substring => 'rails'
|
283
283
|
# #=> thor list --all --substring=rails
|
284
284
|
#
|
285
|
-
def thor(
|
285
|
+
def thor(command, *args)
|
286
286
|
config = args.last.is_a?(Hash) ? args.pop : {}
|
287
287
|
verbose = config.key?(:verbose) ? config.delete(:verbose) : true
|
288
288
|
pretend = config.key?(:pretend) ? config.delete(:pretend) : false
|
289
289
|
capture = config.key?(:capture) ? config.delete(:capture) : false
|
290
290
|
|
291
|
-
args.unshift
|
291
|
+
args.unshift(command)
|
292
292
|
args.push Thor::Options.to_switches(config)
|
293
293
|
command = args.join(' ').strip
|
294
294
|
|
@@ -305,12 +305,12 @@ class Thor
|
|
305
305
|
|
306
306
|
def _cleanup_options_and_set(options, key) #:nodoc:
|
307
307
|
case options
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
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
314
|
end
|
315
315
|
end
|
316
316
|
|
@@ -38,6 +38,8 @@ class Thor
|
|
38
38
|
# destination<String>:: the relative path to the destination root.
|
39
39
|
# config<Hash>:: give :verbose => false to not log the status.
|
40
40
|
# If :recursive => false, does not look for paths recursively.
|
41
|
+
# If :mode => :preserve, preserve the file mode from the source.
|
42
|
+
# If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
|
41
43
|
#
|
42
44
|
# ==== Examples
|
43
45
|
#
|
@@ -73,26 +75,45 @@ class Thor
|
|
73
75
|
def execute!
|
74
76
|
lookup = Util.escape_globs(source)
|
75
77
|
lookup = config[:recursive] ? File.join(lookup, '**') : lookup
|
76
|
-
lookup =
|
78
|
+
lookup = file_level_lookup(lookup)
|
77
79
|
|
78
|
-
|
80
|
+
files(lookup).sort.each do |file_source|
|
79
81
|
next if File.directory?(file_source)
|
82
|
+
next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
|
80
83
|
file_destination = File.join(given_destination, file_source.gsub(source, '.'))
|
81
84
|
file_destination.gsub!('/./', '/')
|
82
85
|
|
83
86
|
case file_source
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
87
|
+
when /\.empty_directory$/
|
88
|
+
dirname = File.dirname(file_destination).gsub(/\/\.$/, '')
|
89
|
+
next if dirname == given_destination
|
90
|
+
base.empty_directory(dirname, config)
|
91
|
+
when /\.tt$/
|
92
|
+
destination = base.template(file_source, file_destination[0..-4], config, &@block)
|
93
|
+
else
|
94
|
+
destination = base.copy_file(file_source, file_destination, config, &@block)
|
92
95
|
end
|
93
96
|
end
|
94
97
|
end
|
95
98
|
|
99
|
+
if RUBY_VERSION < '2.0'
|
100
|
+
def file_level_lookup(previous_lookup)
|
101
|
+
File.join(previous_lookup, '{*,.[a-z]*}')
|
102
|
+
end
|
103
|
+
|
104
|
+
def files(lookup)
|
105
|
+
Dir[lookup]
|
106
|
+
end
|
107
|
+
else
|
108
|
+
def file_level_lookup(previous_lookup)
|
109
|
+
File.join(previous_lookup, '*')
|
110
|
+
end
|
111
|
+
|
112
|
+
def files(lookup)
|
113
|
+
Dir.glob(lookup, File::FNM_DOTMATCH)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
96
117
|
end
|
97
118
|
end
|
98
119
|
end
|
@@ -97,28 +97,12 @@ class Thor
|
|
97
97
|
#
|
98
98
|
# user.rb
|
99
99
|
#
|
100
|
-
# The method referenced
|
101
|
-
# get the exception with the corresponding error message.
|
100
|
+
# The method referenced can be either public or private.
|
102
101
|
#
|
103
102
|
def convert_encoded_instructions(filename)
|
104
103
|
filename.gsub(/%(.*?)%/) do |initial_string|
|
105
|
-
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
# Calls `base`'s public method `sym`.
|
110
|
-
# Returns:: result of `base.sym` or `nil` if `sym` wasn't found in
|
111
|
-
# `base`
|
112
|
-
# Raises:: Thor::PrivateMethodEncodedError if `sym` references
|
113
|
-
# a private method.
|
114
|
-
def call_public_method(sym)
|
115
|
-
if base.respond_to?(sym)
|
116
|
-
base.send(sym)
|
117
|
-
elsif base.respond_to?(sym, true)
|
118
|
-
raise Thor::PrivateMethodEncodedError,
|
119
|
-
"Method #{base.class}##{sym} should be public, not private"
|
120
|
-
else
|
121
|
-
nil
|
104
|
+
method = $1.strip
|
105
|
+
base.respond_to?(method, true) ? base.send(method) : initial_string
|
122
106
|
end
|
123
107
|
end
|
124
108
|
|
@@ -10,7 +10,9 @@ class Thor
|
|
10
10
|
# ==== Parameters
|
11
11
|
# source<String>:: the relative path to the source root.
|
12
12
|
# destination<String>:: the relative path to the destination root.
|
13
|
-
# config<Hash>:: give :verbose => false to not log the status
|
13
|
+
# config<Hash>:: give :verbose => false to not log the status, and
|
14
|
+
# :mode => :preserve, to preserve the file mode from the source.
|
15
|
+
|
14
16
|
#
|
15
17
|
# ==== Examples
|
16
18
|
#
|
@@ -28,6 +30,10 @@ class Thor
|
|
28
30
|
content = block.call(content) if block
|
29
31
|
content
|
30
32
|
end
|
33
|
+
if config[:mode] == :preserve
|
34
|
+
mode = File.stat(source).mode
|
35
|
+
chmod(destination, mode, config)
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
# Links the file from the relative source to the relative destination. If
|
@@ -123,7 +129,7 @@ class Thor
|
|
123
129
|
#
|
124
130
|
# ==== Example
|
125
131
|
#
|
126
|
-
# chmod "script
|
132
|
+
# chmod "script/server", 0755
|
127
133
|
#
|
128
134
|
def chmod(path, mode, config={})
|
129
135
|
return unless behavior == :invoke
|
@@ -245,7 +251,7 @@ class Thor
|
|
245
251
|
def uncomment_lines(path, flag, *args)
|
246
252
|
flag = flag.respond_to?(:source) ? flag.source : flag
|
247
253
|
|
248
|
-
gsub_file(path, /^(\s*)
|
254
|
+
gsub_file(path, /^(\s*)#[[:blank:]]*(.*#{flag})/, '\1\2', *args)
|
249
255
|
end
|
250
256
|
|
251
257
|
# Comment all lines matching a given regex. It will leave the space
|
@@ -1,15 +1,16 @@
|
|
1
|
+
require 'thor/command'
|
1
2
|
require 'thor/core_ext/hash_with_indifferent_access'
|
2
3
|
require 'thor/core_ext/ordered_hash'
|
3
4
|
require 'thor/error'
|
4
|
-
require 'thor/shell'
|
5
5
|
require 'thor/invocation'
|
6
6
|
require 'thor/parser'
|
7
|
-
require 'thor/
|
7
|
+
require 'thor/shell'
|
8
8
|
require 'thor/util'
|
9
9
|
|
10
10
|
class Thor
|
11
11
|
autoload :Actions, 'thor/actions'
|
12
12
|
autoload :RakeCompat, 'thor/rake_compat'
|
13
|
+
autoload :Group, 'thor/group'
|
13
14
|
|
14
15
|
# Shortcuts for help.
|
15
16
|
HELP_MAPPINGS = %w(-h -? --help -D)
|
@@ -46,8 +47,8 @@ class Thor
|
|
46
47
|
# first two parameters.
|
47
48
|
|
48
49
|
if options.is_a?(Array)
|
49
|
-
|
50
|
-
parse_options = parse_options.merge(
|
50
|
+
command_options = config.delete(:command_options) # hook for start
|
51
|
+
parse_options = parse_options.merge(command_options) if command_options
|
51
52
|
array_options, hash_options = options, {}
|
52
53
|
else
|
53
54
|
# Handle the case where the class was explicitly instantiated
|
@@ -58,8 +59,10 @@ class Thor
|
|
58
59
|
# Let Thor::Options parse the options first, so it can remove
|
59
60
|
# declared options from the array. This will leave us with
|
60
61
|
# a list of arguments that weren't declared.
|
61
|
-
|
62
|
+
stop_on_unknown = self.class.stop_on_unknown_option? config[:current_command]
|
63
|
+
opts = Thor::Options.new(parse_options, hash_options, stop_on_unknown)
|
62
64
|
self.options = opts.parse(array_options)
|
65
|
+
self.options = config[:class_options].merge(self.options) if config[:class_options]
|
63
66
|
|
64
67
|
# If unknown options are disallowed, make sure that none of the
|
65
68
|
# remaining arguments looks like an option.
|
@@ -74,7 +77,7 @@ class Thor
|
|
74
77
|
to_parse += opts.remaining unless self.class.strict_args_position?(config)
|
75
78
|
|
76
79
|
thor_args = Thor::Arguments.new(self.class.arguments)
|
77
|
-
thor_args.parse(to_parse).each { |k,v|
|
80
|
+
thor_args.parse(to_parse).each { |k,v| __send__("#{k}=", v) }
|
78
81
|
@args = thor_args.remaining
|
79
82
|
end
|
80
83
|
|
@@ -117,15 +120,15 @@ class Thor
|
|
117
120
|
|
118
121
|
module ClassMethods
|
119
122
|
def attr_reader(*) #:nodoc:
|
120
|
-
|
123
|
+
no_commands { super }
|
121
124
|
end
|
122
125
|
|
123
126
|
def attr_writer(*) #:nodoc:
|
124
|
-
|
127
|
+
no_commands { super }
|
125
128
|
end
|
126
129
|
|
127
130
|
def attr_accessor(*) #:nodoc:
|
128
|
-
|
131
|
+
no_commands { super }
|
129
132
|
end
|
130
133
|
|
131
134
|
# If you want to raise an error for unknown options, call check_unknown_options!
|
@@ -142,6 +145,13 @@ class Thor
|
|
142
145
|
!!check_unknown_options
|
143
146
|
end
|
144
147
|
|
148
|
+
# If true, option parsing is suspended as soon as an unknown option or a
|
149
|
+
# regular argument is encountered. All remaining arguments are passed to
|
150
|
+
# the command as regular arguments.
|
151
|
+
def stop_on_unknown_option?(command_name) #:nodoc:
|
152
|
+
false
|
153
|
+
end
|
154
|
+
|
145
155
|
# If you want only strict string args (useful when cascading thor classes),
|
146
156
|
# call strict_args_position! This is disabled by default to allow dynamic
|
147
157
|
# invocations.
|
@@ -163,11 +173,11 @@ class Thor
|
|
163
173
|
# is how they are parsed from the command line, arguments are retrieved
|
164
174
|
# from position:
|
165
175
|
#
|
166
|
-
# thor
|
176
|
+
# thor command NAME
|
167
177
|
#
|
168
178
|
# Instead of:
|
169
179
|
#
|
170
|
-
# thor
|
180
|
+
# thor command --name=NAME
|
171
181
|
#
|
172
182
|
# Besides, arguments are used inside your code as an accessor (self.argument),
|
173
183
|
# while options are all kept in a hash (self.options).
|
@@ -194,7 +204,7 @@ class Thor
|
|
194
204
|
#
|
195
205
|
def argument(name, options={})
|
196
206
|
is_thor_reserved_word?(name, :argument)
|
197
|
-
|
207
|
+
no_commands { attr_accessor name }
|
198
208
|
|
199
209
|
required = if options.key?(:optional)
|
200
210
|
!options[:optional]
|
@@ -298,88 +308,92 @@ class Thor
|
|
298
308
|
end
|
299
309
|
|
300
310
|
# Defines the group. This is used when thor list is invoked so you can specify
|
301
|
-
# that only
|
311
|
+
# that only commands from a pre-defined group will be shown. Defaults to standard.
|
302
312
|
#
|
303
313
|
# ==== Parameters
|
304
314
|
# name<String|Symbol>
|
305
315
|
#
|
306
316
|
def group(name=nil)
|
307
|
-
case name
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
317
|
+
@group = case name
|
318
|
+
when nil
|
319
|
+
@group || from_superclass(:group, 'standard')
|
320
|
+
else
|
321
|
+
name.to_s
|
312
322
|
end
|
313
323
|
end
|
314
324
|
|
315
|
-
# Returns the
|
325
|
+
# Returns the commands for this Thor class.
|
316
326
|
#
|
317
327
|
# ==== Returns
|
318
|
-
# OrderedHash:: An ordered hash with
|
328
|
+
# OrderedHash:: An ordered hash with commands names as keys and Thor::Command
|
319
329
|
# objects as values.
|
320
330
|
#
|
321
|
-
def
|
322
|
-
@
|
331
|
+
def commands
|
332
|
+
@commands ||= Thor::CoreExt::OrderedHash.new
|
323
333
|
end
|
334
|
+
alias tasks commands
|
324
335
|
|
325
|
-
# Returns the
|
336
|
+
# Returns the commands for this Thor class and all subclasses.
|
326
337
|
#
|
327
338
|
# ==== Returns
|
328
|
-
# OrderedHash:: An ordered hash with
|
339
|
+
# OrderedHash:: An ordered hash with commands names as keys and Thor::Command
|
329
340
|
# objects as values.
|
330
341
|
#
|
331
|
-
def
|
332
|
-
@
|
333
|
-
@
|
342
|
+
def all_commands
|
343
|
+
@all_commands ||= from_superclass(:all_commands, Thor::CoreExt::OrderedHash.new)
|
344
|
+
@all_commands.merge(commands)
|
334
345
|
end
|
346
|
+
alias all_tasks all_commands
|
335
347
|
|
336
|
-
# Removes a given
|
348
|
+
# Removes a given command from this Thor class. This is usually done if you
|
337
349
|
# are inheriting from another class and don't want it to be available
|
338
350
|
# anymore.
|
339
351
|
#
|
340
|
-
# By default it only remove the mapping to the
|
352
|
+
# By default it only remove the mapping to the command. But you can supply
|
341
353
|
# :undefine => true to undefine the method from the class as well.
|
342
354
|
#
|
343
355
|
# ==== Parameters
|
344
|
-
# name<Symbol|String>:: The name of the
|
345
|
-
# options<Hash>:: You can give :undefine => true if you want
|
356
|
+
# name<Symbol|String>:: The name of the command to be removed
|
357
|
+
# options<Hash>:: You can give :undefine => true if you want commands the method
|
346
358
|
# to be undefined from the class as well.
|
347
359
|
#
|
348
|
-
def
|
360
|
+
def remove_command(*names)
|
349
361
|
options = names.last.is_a?(Hash) ? names.pop : {}
|
350
362
|
|
351
363
|
names.each do |name|
|
352
|
-
|
353
|
-
|
364
|
+
commands.delete(name.to_s)
|
365
|
+
all_commands.delete(name.to_s)
|
354
366
|
undef_method name if options[:undefine]
|
355
367
|
end
|
356
368
|
end
|
369
|
+
alias remove_task remove_command
|
357
370
|
|
358
|
-
# All methods defined inside the given block are not added as
|
371
|
+
# All methods defined inside the given block are not added as commands.
|
359
372
|
#
|
360
373
|
# So you can do:
|
361
374
|
#
|
362
375
|
# class MyScript < Thor
|
363
|
-
#
|
364
|
-
# def
|
376
|
+
# no_commands do
|
377
|
+
# def this_is_not_a_command
|
365
378
|
# end
|
366
379
|
# end
|
367
380
|
# end
|
368
381
|
#
|
369
|
-
# You can also add the method and remove it from the
|
382
|
+
# You can also add the method and remove it from the command list:
|
370
383
|
#
|
371
384
|
# class MyScript < Thor
|
372
|
-
# def
|
385
|
+
# def this_is_not_a_command
|
373
386
|
# end
|
374
|
-
#
|
387
|
+
# remove_command :this_is_not_a_command
|
375
388
|
# end
|
376
389
|
#
|
377
|
-
def
|
378
|
-
@
|
390
|
+
def no_commands
|
391
|
+
@no_commands = true
|
379
392
|
yield
|
380
393
|
ensure
|
381
|
-
@
|
394
|
+
@no_commands = false
|
382
395
|
end
|
396
|
+
alias no_tasks no_commands
|
383
397
|
|
384
398
|
# Sets the namespace for the Thor or Thor::Group class. By default the
|
385
399
|
# namespace is retrieved from the class name. If your Thor class is named
|
@@ -391,7 +405,7 @@ class Thor
|
|
391
405
|
#
|
392
406
|
# namespace :my_scripts
|
393
407
|
#
|
394
|
-
# You change how your
|
408
|
+
# You change how your commands are invoked:
|
395
409
|
#
|
396
410
|
# thor my_scripts -h
|
397
411
|
#
|
@@ -399,26 +413,26 @@ class Thor
|
|
399
413
|
#
|
400
414
|
# namespace :default
|
401
415
|
#
|
402
|
-
# Your
|
416
|
+
# Your commands can be invoked with a shortcut. Instead of:
|
403
417
|
#
|
404
|
-
# thor :
|
418
|
+
# thor :my_command
|
405
419
|
#
|
406
420
|
def namespace(name=nil)
|
407
|
-
case name
|
421
|
+
@namespace = case name
|
408
422
|
when nil
|
409
|
-
@namespace
|
423
|
+
@namespace || Thor::Util.namespace_from_thor_class(self)
|
410
424
|
else
|
411
425
|
@namespace = name.to_s
|
412
426
|
end
|
413
427
|
end
|
414
428
|
|
415
|
-
# Parses the
|
416
|
-
# and invoke the
|
429
|
+
# Parses the command and options from the given args, instantiate the class
|
430
|
+
# and invoke the command. This method is used when the arguments must be parsed
|
417
431
|
# from an array. If you are inside Ruby and want to use a Thor class, you
|
418
432
|
# can simply initialize it:
|
419
433
|
#
|
420
434
|
# script = MyScript.new(args, options, config)
|
421
|
-
# script.invoke(:
|
435
|
+
# script.invoke(:command, first_arg, second_arg, third_arg)
|
422
436
|
#
|
423
437
|
def start(given_args=ARGV, config={})
|
424
438
|
config[:shell] ||= Thor::Base.shell.new
|
@@ -427,48 +441,44 @@ class Thor
|
|
427
441
|
ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.message)
|
428
442
|
exit(1) if exit_on_failure?
|
429
443
|
rescue Errno::EPIPE
|
430
|
-
# This happens if a thor
|
444
|
+
# This happens if a thor command is piped to something like `head`,
|
431
445
|
# which closes the pipe when it's done reading. This will also
|
432
446
|
# mean that if the pipe is closed, further unnecessary
|
433
447
|
# computation will not occur.
|
434
448
|
exit(0)
|
435
449
|
end
|
436
450
|
|
437
|
-
# Allows to use private methods from parent in child classes as
|
451
|
+
# Allows to use private methods from parent in child classes as commands.
|
438
452
|
#
|
439
453
|
# ==== Parameters
|
440
|
-
# names<Array>:: Method names to be used as
|
454
|
+
# names<Array>:: Method names to be used as commands
|
441
455
|
#
|
442
456
|
# ==== Examples
|
443
457
|
#
|
444
|
-
#
|
445
|
-
#
|
458
|
+
# public_command :foo
|
459
|
+
# public_command :foo, :bar, :baz
|
446
460
|
#
|
447
|
-
def
|
461
|
+
def public_command(*names)
|
448
462
|
names.each do |name|
|
449
463
|
class_eval "def #{name}(*); super end"
|
450
464
|
end
|
451
465
|
end
|
466
|
+
alias public_task public_command
|
452
467
|
|
453
|
-
def
|
468
|
+
def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc:
|
454
469
|
if has_namespace
|
455
|
-
raise
|
470
|
+
raise UndefinedCommandError, "Could not find command #{command.inspect} in #{namespace.inspect} namespace."
|
456
471
|
else
|
457
|
-
raise
|
472
|
+
raise UndefinedCommandError, "Could not find command #{command.inspect}."
|
458
473
|
end
|
459
474
|
end
|
475
|
+
alias handle_no_task_error handle_no_command_error
|
460
476
|
|
461
|
-
def handle_argument_error(
|
462
|
-
msg = "#{basename} #{
|
463
|
-
if
|
464
|
-
|
465
|
-
|
466
|
-
msg << "s" if required > 1
|
467
|
-
else
|
468
|
-
msg = "call #{msg} as"
|
469
|
-
end
|
470
|
-
|
471
|
-
msg << ": #{self.banner(task).inspect}."
|
477
|
+
def handle_argument_error(command, error, args, arity) #:nodoc:
|
478
|
+
msg = "ERROR: #{basename} #{command.name} was called with "
|
479
|
+
msg << 'no arguments' if args.empty?
|
480
|
+
msg << 'arguments ' << args.inspect if !args.empty?
|
481
|
+
msg << "\nUsage: #{self.banner(command).inspect}."
|
472
482
|
raise InvocationError, msg
|
473
483
|
end
|
474
484
|
|
@@ -546,28 +556,29 @@ class Thor
|
|
546
556
|
end
|
547
557
|
end
|
548
558
|
|
549
|
-
# Finds a
|
559
|
+
# Finds a command with the given name. If the command belongs to the current
|
550
560
|
# class, just return it, otherwise dup it and add the fresh copy to the
|
551
|
-
# current
|
552
|
-
def
|
553
|
-
|
554
|
-
|
555
|
-
elsif
|
556
|
-
|
561
|
+
# current command hash.
|
562
|
+
def find_and_refresh_command(name) #:nodoc:
|
563
|
+
command = if command = commands[name.to_s]
|
564
|
+
command
|
565
|
+
elsif command = all_commands[name.to_s]
|
566
|
+
commands[name.to_s] = command.clone
|
557
567
|
else
|
558
|
-
raise ArgumentError, "You supplied :for => #{name.inspect}, but the
|
568
|
+
raise ArgumentError, "You supplied :for => #{name.inspect}, but the command #{name.inspect} could not be found."
|
559
569
|
end
|
560
570
|
end
|
571
|
+
alias find_and_refresh_task find_and_refresh_command
|
561
572
|
|
562
573
|
# Everytime someone inherits from a Thor class, register the klass
|
563
574
|
# and file into baseclass.
|
564
575
|
def inherited(klass)
|
565
576
|
Thor::Base.register_klass_file(klass)
|
566
|
-
klass.instance_variable_set(:@
|
577
|
+
klass.instance_variable_set(:@no_commands, false)
|
567
578
|
end
|
568
579
|
|
569
580
|
# Fire this callback whenever a method is added. Added methods are
|
570
|
-
# tracked as
|
581
|
+
# tracked as commands by invoking the create_command method.
|
571
582
|
def method_added(meth)
|
572
583
|
meth = meth.to_s
|
573
584
|
|
@@ -577,12 +588,11 @@ class Thor
|
|
577
588
|
end
|
578
589
|
|
579
590
|
# Return if it's not a public instance method
|
580
|
-
return unless
|
581
|
-
public_instance_methods.include?(meth.to_sym)
|
591
|
+
return unless public_method_defined?(meth.to_sym)
|
582
592
|
|
583
|
-
return if @
|
593
|
+
return if @no_commands || !create_command(meth)
|
584
594
|
|
585
|
-
is_thor_reserved_word?(meth, :
|
595
|
+
is_thor_reserved_word?(meth, :command)
|
586
596
|
Thor::Base.register_klass_file(self)
|
587
597
|
end
|
588
598
|
|
@@ -621,10 +631,11 @@ class Thor
|
|
621
631
|
def baseclass #:nodoc:
|
622
632
|
end
|
623
633
|
|
624
|
-
# SIGNATURE: Creates a new
|
634
|
+
# SIGNATURE: Creates a new command if valid_command? is true. This method is
|
625
635
|
# called when a new method is added to the class.
|
626
|
-
def
|
636
|
+
def create_command(meth) #:nodoc:
|
627
637
|
end
|
638
|
+
alias create_task create_command
|
628
639
|
|
629
640
|
# SIGNATURE: Defines behavior when the initialize method is added to the
|
630
641
|
# class.
|
@@ -632,7 +643,7 @@ class Thor
|
|
632
643
|
end
|
633
644
|
|
634
645
|
# SIGNATURE: The hook invoked by start.
|
635
|
-
def dispatch(
|
646
|
+
def dispatch(command, given_args, given_opts, config) #:nodoc:
|
636
647
|
raise NotImplementedError
|
637
648
|
end
|
638
649
|
|