Struct.new(:name, :description, :long_description, :usage, :options)
Returns the formatted usage by injecting given required arguments and required options into the given usage.
# File lib/thor/task.rb, line 33
33: def formatted_usage(klass, namespace = true, subcommand = false)
34: if namespace
35: namespace = klass.namespace
36: formatted = "#{namespace.gsub(/^(default)/,'')}:"
37: formatted.sub!(/.$/, ' ') if subcommand
38: end
39:
40: formatted ||= ""
41:
42: # Add usage with required arguments
43: formatted << if klass && !klass.arguments.empty?
44: usage.to_s.gsub(/^#{name}/) do |match|
45: match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
46: end
47: else
48: usage.to_s
49: end
50:
51: # Add required options
52: formatted << " #{required_options}"
53:
54: # Strip and go!
55: formatted.strip
56: end
By default, a task invokes a method in the thor class. You can change this implementation to create custom tasks.
# File lib/thor/task.rb, line 20
20: def run(instance, args=[])
21: public_method?(instance) ?
22: instance.send(name, *args) : instance.class.handle_no_task_error(name)
23: rescue ArgumentError => e
24: handle_argument_error?(instance, e, caller) ?
25: instance.class.handle_argument_error(self, e) : (raise e)
26: rescue NoMethodError => e
27: handle_no_method_error?(instance, e, caller) ?
28: instance.class.handle_no_task_error(name) : (raise e)
29: end
# File lib/thor/task.rb, line 79
79: def handle_argument_error?(instance, error, caller)
80: not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin
81: saned = sans_backtrace(error.backtrace, caller)
82: # Ruby 1.9 always include the called method in the backtrace
83: saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9")
84: end
85: end
# File lib/thor/task.rb, line 87
87: def handle_no_method_error?(instance, error, caller)
88: not_debugging?(instance) &&
89: error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/
90: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.