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 def formatted_usage(klass, namespace = true, subcommand = false) if namespace namespace = klass.namespace formatted = "#{namespace.gsub(/^(default)/,'')}:" formatted.sub!(/.$/, ' ') if subcommand end formatted ||= "" # Add usage with required arguments formatted << if klass && !klass.arguments.empty? usage.to_s.gsub(/^#{name}/) do |match| match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ') end else usage.to_s end # Add required options formatted << " #{required_options}" # Strip and go! formatted.strip 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 def run(instance, args=[]) public_method?(instance) ? instance.send(name, *args) : instance.class.handle_no_task_error(name) rescue ArgumentError => e handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e) : (raise e) rescue NoMethodError => e handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_task_error(name) : (raise e) end
# File lib/thor/task.rb, line 79 def handle_argument_error?(instance, error, caller) not_debugging?(instance) && error.message =~ /wrong number of arguments/ && begin saned = sans_backtrace(error.backtrace, caller) # Ruby 1.9 always include the called method in the backtrace saned.empty? || (saned.size == 1 && RUBY_VERSION >= "1.9") end end
# File lib/thor/task.rb, line 87 def handle_no_method_error?(instance, error, caller) not_debugging?(instance) && error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ end
Generated with the Darkfish Rdoc Generator 2.