engineyard-serverside 2.0.0 → 2.0.1

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.
Files changed (36) hide show
  1. data/lib/engineyard-serverside/paths.rb +0 -1
  2. data/lib/engineyard-serverside/version.rb +1 -1
  3. data/lib/vendor/thor/{LICENSE → LICENSE.md} +2 -2
  4. data/lib/vendor/thor/README.md +28 -0
  5. data/lib/vendor/thor/lib/thor.rb +183 -48
  6. data/lib/vendor/thor/lib/thor/actions.rb +66 -23
  7. data/lib/vendor/thor/lib/thor/actions/create_file.rb +5 -3
  8. data/lib/vendor/thor/lib/thor/actions/create_link.rb +57 -0
  9. data/lib/vendor/thor/lib/thor/actions/directory.rb +14 -7
  10. data/lib/vendor/thor/lib/thor/actions/empty_directory.rb +24 -5
  11. data/lib/vendor/thor/lib/thor/actions/file_manipulation.rb +106 -21
  12. data/lib/vendor/thor/lib/thor/actions/inject_into_file.rb +15 -10
  13. data/lib/vendor/thor/lib/thor/base.rb +144 -43
  14. data/lib/vendor/thor/lib/thor/core_ext/dir_escape.rb +0 -0
  15. data/lib/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +1 -1
  16. data/lib/vendor/thor/lib/thor/error.rb +6 -1
  17. data/lib/vendor/thor/lib/thor/group.rb +41 -27
  18. data/lib/vendor/thor/lib/thor/invocation.rb +48 -58
  19. data/lib/vendor/thor/lib/thor/parser/argument.rb +29 -22
  20. data/lib/vendor/thor/lib/thor/parser/arguments.rb +26 -5
  21. data/lib/vendor/thor/lib/thor/parser/option.rb +42 -49
  22. data/lib/vendor/thor/lib/thor/parser/options.rb +39 -30
  23. data/lib/vendor/thor/lib/thor/rake_compat.rb +13 -8
  24. data/lib/vendor/thor/lib/thor/runner.rb +27 -20
  25. data/lib/vendor/thor/lib/thor/shell.rb +10 -5
  26. data/lib/vendor/thor/lib/thor/shell/basic.rb +228 -78
  27. data/lib/vendor/thor/lib/thor/shell/color.rb +40 -4
  28. data/lib/vendor/thor/lib/thor/shell/html.rb +123 -0
  29. data/lib/vendor/thor/lib/thor/task.rb +83 -53
  30. data/lib/vendor/thor/lib/thor/util.rb +57 -21
  31. data/lib/vendor/thor/lib/thor/version.rb +1 -1
  32. data/lib/vendor/thor/thor.gemspec +21 -115
  33. metadata +109 -217
  34. data/lib/vendor/thor/CHANGELOG.rdoc +0 -89
  35. data/lib/vendor/thor/README.rdoc +0 -297
  36. data/lib/vendor/thor/Thorfile +0 -69
@@ -19,7 +19,7 @@ class Thor
19
19
  action add_file create_file in_root inside run run_ruby_script)
20
20
 
21
21
  module Base
22
- attr_accessor :options
22
+ attr_accessor :options, :parent_options, :args
23
23
 
24
24
  # It receives arguments in an Array and two hashes, one for options and
25
25
  # other for configuration.
@@ -38,22 +38,44 @@ class Thor
38
38
  # config<Hash>:: Configuration for this Thor class.
39
39
  #
40
40
  def initialize(args=[], options={}, config={})
41
- args = Thor::Arguments.parse(self.class.arguments, args)
42
- args.each { |key, value| send("#{key}=", value) }
43
-
44
41
  parse_options = self.class.class_options
45
42
 
43
+ # The start method splits inbound arguments at the first argument
44
+ # that looks like an option (starts with - or --). It then calls
45
+ # new, passing in the two halves of the arguments Array as the
46
+ # first two parameters.
47
+
46
48
  if options.is_a?(Array)
47
49
  task_options = config.delete(:task_options) # hook for start
48
50
  parse_options = parse_options.merge(task_options) if task_options
49
51
  array_options, hash_options = options, {}
50
52
  else
53
+ # Handle the case where the class was explicitly instantiated
54
+ # with pre-parsed options.
51
55
  array_options, hash_options = [], options
52
56
  end
53
57
 
58
+ # Let Thor::Options parse the options first, so it can remove
59
+ # declared options from the array. This will leave us with
60
+ # a list of arguments that weren't declared.
54
61
  opts = Thor::Options.new(parse_options, hash_options)
55
62
  self.options = opts.parse(array_options)
56
- opts.check_unknown! if self.class.check_unknown_options?
63
+
64
+ # If unknown options are disallowed, make sure that none of the
65
+ # remaining arguments looks like an option.
66
+ opts.check_unknown! if self.class.check_unknown_options?(config)
67
+
68
+ # Add the remaining arguments from the options parser to the
69
+ # arguments passed in to initialize. Then remove any positional
70
+ # arguments declared using #argument (this is primarily used
71
+ # by Thor::Group). Tis will leave us with the remaining
72
+ # positional arguments.
73
+ to_parse = args
74
+ to_parse += opts.remaining unless self.class.strict_args_position?(config)
75
+
76
+ thor_args = Thor::Arguments.new(self.class.arguments)
77
+ thor_args.parse(to_parse).each { |k,v| send("#{k}=", v) }
78
+ @args = thor_args.remaining
57
79
  end
58
80
 
59
81
  class << self
@@ -94,8 +116,6 @@ class Thor
94
116
  end
95
117
 
96
118
  module ClassMethods
97
- attr_accessor :debugging
98
-
99
119
  def attr_reader(*) #:nodoc:
100
120
  no_tasks { super }
101
121
  end
@@ -114,8 +134,27 @@ class Thor
114
134
  @check_unknown_options = true
115
135
  end
116
136
 
117
- def check_unknown_options? #:nodoc:
118
- @check_unknown_options || false
137
+ def check_unknown_options #:nodoc:
138
+ @check_unknown_options ||= from_superclass(:check_unknown_options, false)
139
+ end
140
+
141
+ def check_unknown_options?(config) #:nodoc:
142
+ !!check_unknown_options
143
+ end
144
+
145
+ # If you want only strict string args (useful when cascading thor classes),
146
+ # call strict_args_position! This is disabled by default to allow dynamic
147
+ # invocations.
148
+ def strict_args_position!
149
+ @strict_args_position = true
150
+ end
151
+
152
+ def strict_args_position #:nodoc:
153
+ @strict_args_position ||= from_superclass(:strict_args_position, false)
154
+ end
155
+
156
+ def strict_args_position?(config) #:nodoc:
157
+ !!strict_args_position
119
158
  end
120
159
 
121
160
  # Adds an argument to the class and creates an attr_accessor for it.
@@ -173,8 +212,9 @@ class Thor
173
212
  "the non-required argument #{argument.human_name.inspect}."
174
213
  end if required
175
214
 
176
- arguments << Thor::Argument.new(name, options[:desc], required, options[:type],
177
- options[:default], options[:banner])
215
+ options[:required] = required
216
+
217
+ arguments << Thor::Argument.new(name, options)
178
218
  end
179
219
 
180
220
  # Returns this class arguments, looking up in the ancestors chain.
@@ -208,13 +248,14 @@ class Thor
208
248
  # options<Hash>:: Described below.
209
249
  #
210
250
  # ==== Options
211
- # :desc - Description for the argument.
212
- # :required - If the argument is required or not.
213
- # :default - Default value for this argument.
214
- # :group - The group for this options. Use by class options to output options in different levels.
215
- # :aliases - Aliases for this option.
216
- # :type - The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
217
- # :banner - String to show on usage notes.
251
+ # :desc:: -- Description for the argument.
252
+ # :required:: -- If the argument is required or not.
253
+ # :default:: -- Default value for this argument.
254
+ # :group:: -- The group for this options. Use by class options to output options in different levels.
255
+ # :aliases:: -- Aliases for this option. <b>Note:</b> Thor follows a convention of one-dash-one-letter options. Thus aliases like "-something" wouldn't be parsed; use either "\--something" or "-s" instead.
256
+ # :type:: -- The type of the argument, can be :string, :hash, :array, :numeric or :boolean.
257
+ # :banner:: -- String to show on usage notes.
258
+ # :hide:: -- If you want to hide this option from the help.
218
259
  #
219
260
  def class_option(name, options={})
220
261
  build_option(name, options, class_options)
@@ -223,7 +264,7 @@ class Thor
223
264
  # Removes a previous defined argument. If :undefine is given, undefine
224
265
  # accessors as well.
225
266
  #
226
- # ==== Paremeters
267
+ # ==== Parameters
227
268
  # names<Array>:: Arguments to be removed
228
269
  #
229
270
  # ==== Examples
@@ -242,7 +283,7 @@ class Thor
242
283
 
243
284
  # Removes a previous defined class option.
244
285
  #
245
- # ==== Paremeters
286
+ # ==== Parameters
246
287
  # names<Array>:: Class options to be removed
247
288
  #
248
289
  # ==== Examples
@@ -336,6 +377,7 @@ class Thor
336
377
  def no_tasks
337
378
  @no_tasks = true
338
379
  yield
380
+ ensure
339
381
  @no_tasks = false
340
382
  end
341
383
 
@@ -363,32 +405,73 @@ class Thor
363
405
  #
364
406
  def namespace(name=nil)
365
407
  case name
366
- when nil
367
- @namespace ||= Thor::Util.namespace_from_thor_class(self)
368
- else
369
- @namespace = name.to_s
408
+ when nil
409
+ @namespace ||= Thor::Util.namespace_from_thor_class(self)
410
+ else
411
+ @namespace = name.to_s
370
412
  end
371
413
  end
372
414
 
373
- # Default way to start generators from the command line.
415
+ # Parses the task and options from the given args, instantiate the class
416
+ # and invoke the task. This method is used when the arguments must be parsed
417
+ # from an array. If you are inside Ruby and want to use a Thor class, you
418
+ # can simply initialize it:
419
+ #
420
+ # script = MyScript.new(args, options, config)
421
+ # script.invoke(:task, first_arg, second_arg, third_arg)
374
422
  #
375
423
  def start(given_args=ARGV, config={})
376
- self.debugging = given_args.include?("--debug")
377
424
  config[:shell] ||= Thor::Base.shell.new
378
- yield(given_args.dup)
425
+ dispatch(nil, given_args.dup, nil, config)
379
426
  rescue Thor::Error => e
380
- debugging ? (raise e) : config[:shell].error(e.message)
427
+ ENV["THOR_DEBUG"] == "1" ? (raise e) : config[:shell].error(e.message)
381
428
  exit(1) if exit_on_failure?
429
+ rescue Errno::EPIPE
430
+ # This happens if a thor task is piped to something like `head`,
431
+ # which closes the pipe when it's done reading. This will also
432
+ # mean that if the pipe is closed, further unnecessary
433
+ # computation will not occur.
434
+ exit(0)
382
435
  end
383
436
 
384
- def handle_no_task_error(task) #:nodoc:
385
- if self.banner_base == "thor"
437
+ # Allows to use private methods from parent in child classes as tasks.
438
+ #
439
+ # ==== Parameters
440
+ # names<Array>:: Method names to be used as tasks
441
+ #
442
+ # ==== Examples
443
+ #
444
+ # public_task :foo
445
+ # public_task :foo, :bar, :baz
446
+ #
447
+ def public_task(*names)
448
+ names.each do |name|
449
+ class_eval "def #{name}(*); super end"
450
+ end
451
+ end
452
+
453
+ def handle_no_task_error(task, has_namespace = $thor_runner) #:nodoc:
454
+ if has_namespace
386
455
  raise UndefinedTaskError, "Could not find task #{task.inspect} in #{namespace.inspect} namespace."
387
456
  else
388
457
  raise UndefinedTaskError, "Could not find task #{task.inspect}."
389
458
  end
390
459
  end
391
460
 
461
+ def handle_argument_error(task, error, arity=nil) #:nodoc:
462
+ msg = "#{basename} #{task.name}"
463
+ if arity
464
+ required = arity < 0 ? (-1 - arity) : arity
465
+ msg << " requires at least #{required} argument"
466
+ msg << "s" if required > 1
467
+ else
468
+ msg = "call #{msg} as"
469
+ end
470
+
471
+ msg << ": #{self.banner(task).inspect}."
472
+ raise InvocationError, msg
473
+ end
474
+
392
475
  protected
393
476
 
394
477
  # Prints the class options per group. If an option does not belong to
@@ -419,15 +502,18 @@ class Thor
419
502
  padding = options.collect{ |o| o.aliases.size }.max.to_i * 4
420
503
 
421
504
  options.each do |option|
422
- item = [ option.usage(padding) ]
423
- item.push(option.description ? "# #{option.description}" : "")
424
-
425
- list << item
426
- list << [ "", "# Default: #{option.default}" ] if option.show_default?
505
+ unless option.hide
506
+ item = [ option.usage(padding) ]
507
+ item.push(option.description ? "# #{option.description}" : "")
508
+
509
+ list << item
510
+ list << [ "", "# Default: #{option.default}" ] if option.show_default?
511
+ list << [ "", "# Possible values: #{option.enum.join(', ')}" ] if option.enum
512
+ end
427
513
  end
428
514
 
429
515
  shell.say(group_name ? "#{group_name} options:" : "Options:")
430
- shell.print_table(list, :ident => 2)
516
+ shell.print_table(list, :indent => 2)
431
517
  shell.say ""
432
518
  end
433
519
 
@@ -442,10 +528,9 @@ class Thor
442
528
  # ==== Parameters
443
529
  # name<Symbol>:: The name of the argument.
444
530
  # options<Hash>:: Described in both class_option and method_option.
531
+ # scope<Hash>:: Options hash that is being built up
445
532
  def build_option(name, options, scope) #:nodoc:
446
- scope[name] = Thor::Option.new(name, options[:desc], options[:required],
447
- options[:type], options[:default], options[:banner],
448
- options[:group], options[:aliases])
533
+ scope[name] = Thor::Option.new(name, options)
449
534
  end
450
535
 
451
536
  # Receives a hash of options, parse them and add to the scope. This is a
@@ -478,6 +563,7 @@ class Thor
478
563
  # and file into baseclass.
479
564
  def inherited(klass)
480
565
  Thor::Base.register_klass_file(klass)
566
+ klass.instance_variable_set(:@no_tasks, false)
481
567
  end
482
568
 
483
569
  # Fire this callback whenever a method is added. Added methods are
@@ -507,7 +593,14 @@ class Thor
507
593
  default
508
594
  else
509
595
  value = superclass.send(method)
510
- value.dup if value
596
+
597
+ if value
598
+ if value.is_a?(TrueClass) || value.is_a?(Symbol)
599
+ value
600
+ else
601
+ value.dup
602
+ end
603
+ end
511
604
  end
512
605
  end
513
606
 
@@ -516,9 +609,11 @@ class Thor
516
609
  false
517
610
  end
518
611
 
519
- # Returns the base for banner.
520
- def banner_base
521
- @banner_base ||= $thor_runner ? "thor" : File.basename($0.split(" ").first)
612
+ #
613
+ # The basename of the program invoking the thor class.
614
+ #
615
+ def basename
616
+ File.basename($0).split(' ').first
522
617
  end
523
618
 
524
619
  # SIGNATURE: Sets the baseclass. This is where the superclass lookup
@@ -535,6 +630,12 @@ class Thor
535
630
  # class.
536
631
  def initialize_added #:nodoc:
537
632
  end
633
+
634
+ # SIGNATURE: The hook invoked by start.
635
+ def dispatch(task, given_args, given_opts, config) #:nodoc:
636
+ raise NotImplementedError
637
+ end
638
+
538
639
  end
539
640
  end
540
641
  end
File without changes
@@ -65,7 +65,7 @@ class Thor
65
65
  else
66
66
  self[$1] == args.first
67
67
  end
68
- else
68
+ else
69
69
  self[method]
70
70
  end
71
71
  end
@@ -1,6 +1,6 @@
1
1
  class Thor
2
2
  # Thor::Error is raised when it's caused by wrong usage of thor classes. Those
3
- # errors have their backtrace supressed and are nicely shown to the user.
3
+ # errors have their backtrace suppressed and are nicely shown to the user.
4
4
  #
5
5
  # Errors that are caused by the developer, like declaring a method which
6
6
  # overwrites a thor keyword, it SHOULD NOT raise a Thor::Error. This way, we
@@ -27,4 +27,9 @@ class Thor
27
27
 
28
28
  class MalformattedArgumentError < InvocationError
29
29
  end
30
+
31
+ # Raised when a user tries to call a private method encoded in templated filename.
32
+ #
33
+ class PrivateMethodEncodedError < Error
34
+ end
30
35
  end
@@ -6,7 +6,7 @@ require 'thor/base'
6
6
  # tasks.
7
7
  class Thor::Group
8
8
  class << self
9
- # The descrition for this Thor::Group. If none is provided, but a source root
9
+ # The description for this Thor::Group. If none is provided, but a source root
10
10
  # exists, tries to find the USAGE one folder above it, otherwise searches
11
11
  # in the superclass.
12
12
  #
@@ -22,21 +22,6 @@ class Thor::Group
22
22
  end
23
23
  end
24
24
 
25
- # Start works differently in Thor::Group, it simply invokes all tasks
26
- # inside the class.
27
- #
28
- def start(original_args=ARGV, config={})
29
- super do |given_args|
30
- if Thor::HELP_MAPPINGS.include?(given_args.first)
31
- help(config[:shell])
32
- return
33
- end
34
-
35
- args, opts = Thor::Options.split(given_args)
36
- new(args, opts, config).invoke
37
- end
38
- end
39
-
40
25
  # Prints help information.
41
26
  #
42
27
  # ==== Options
@@ -119,7 +104,7 @@ class Thor::Group
119
104
  #
120
105
  # ==== Custom invocations
121
106
  #
122
- # You can also supply a block to customize how the option is giong to be
107
+ # You can also supply a block to customize how the option is going to be
123
108
  # invoked. The block receives two parameters, an instance of the current
124
109
  # class and the klass to be invoked.
125
110
  #
@@ -129,7 +114,7 @@ class Thor::Group
129
114
 
130
115
  names.each do |name|
131
116
  unless class_options.key?(name)
132
- raise ArgumentError, "You have to define the option #{name.inspect} " <<
117
+ raise ArgumentError, "You have to define the option #{name.inspect} " <<
133
118
  "before setting invoke_from_option."
134
119
  end
135
120
 
@@ -195,16 +180,16 @@ class Thor::Group
195
180
  end
196
181
  next unless value
197
182
 
198
- klass, task = prepare_for_invocation(name, value)
183
+ klass, _ = prepare_for_invocation(name, value)
199
184
  next unless klass && klass.respond_to?(:class_options)
200
185
 
201
186
  value = value.to_s
202
187
  human_name = value.respond_to?(:classify) ? value.classify : value
203
188
 
204
189
  group_options[human_name] ||= []
205
- group_options[human_name] += klass.class_options.values.select do |option|
206
- base_options[option.name.to_sym].nil? && option.group.nil? &&
207
- !group_options.values.flatten.any? { |i| i.name == option.name }
190
+ group_options[human_name] += klass.class_options.values.select do |class_option|
191
+ base_options[class_option.name.to_sym].nil? && class_option.group.nil? &&
192
+ !group_options.values.flatten.any? { |i| i.name == class_option.name }
208
193
  end
209
194
 
210
195
  yield klass if block_given?
@@ -219,21 +204,50 @@ class Thor::Group
219
204
  [item]
220
205
  end
221
206
 
222
- def handle_argument_error(task, error) #:nodoc:
223
- raise error, "#{task.name.inspect} was called incorrectly. Are you sure it has arity equals to 0?"
207
+ def handle_argument_error(task, error, arity=nil) #:nodoc:
208
+ if arity > 0
209
+ msg = "#{basename} #{task.name} takes #{arity} argument"
210
+ msg << "s" if arity > 1
211
+ msg << ", but it should not."
212
+ else
213
+ msg = "You should not pass arguments to #{basename} #{task.name}."
214
+ end
215
+
216
+ raise error, msg
224
217
  end
225
218
 
226
219
  protected
227
220
 
221
+ # The method responsible for dispatching given the args.
222
+ def dispatch(task, given_args, given_opts, config) #:nodoc:
223
+ if Thor::HELP_MAPPINGS.include?(given_args.first)
224
+ help(config[:shell])
225
+ return
226
+ end
227
+
228
+ args, opts = Thor::Options.split(given_args)
229
+ opts = given_opts || opts
230
+
231
+ instance = new(args, opts, config)
232
+ yield instance if block_given?
233
+ args = instance.args
234
+
235
+ if task
236
+ instance.invoke_task(all_tasks[task])
237
+ else
238
+ instance.invoke_all
239
+ end
240
+ end
241
+
228
242
  # The banner for this class. You can customize it if you are invoking the
229
243
  # thor class by another ways which is not the Thor::Runner.
230
244
  def banner
231
- "#{banner_base} #{self_task.formatted_usage(self, false)}"
245
+ "#{basename} #{self_task.formatted_usage(self, false)}"
232
246
  end
233
247
 
234
248
  # Represents the whole class as a task.
235
249
  def self_task #:nodoc:
236
- Thor::Task::Dynamic.new(self.namespace, class_options)
250
+ Thor::DynamicTask.new(self.namespace, class_options)
237
251
  end
238
252
 
239
253
  def baseclass #:nodoc:
@@ -241,7 +255,7 @@ class Thor::Group
241
255
  end
242
256
 
243
257
  def create_task(meth) #:nodoc:
244
- tasks[meth.to_s] = Thor::Task.new(meth, nil, nil, nil)
258
+ tasks[meth.to_s] = Thor::Task.new(meth, nil, nil, nil, nil)
245
259
  true
246
260
  end
247
261
  end