From 6eea98ae469dfff63334e93299413d4fe07a19f9 Mon Sep 17 00:00:00 2001 From: José Valim Date: Fri, 16 Jul 2010 17:22:47 +0200 Subject: Update vendored Thor. --- lib/bundler/vendor/thor.rb | 14 ++++-- lib/bundler/vendor/thor/base.rb | 1 + lib/bundler/vendor/thor/invocation.rb | 2 +- lib/bundler/vendor/thor/task.rb | 95 +++++++++++++++++++---------------- lib/bundler/vendor/thor/version.rb | 2 +- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/lib/bundler/vendor/thor.rb b/lib/bundler/vendor/thor.rb index c2a1d325..acc547ec 100644 --- a/lib/bundler/vendor/thor.rb +++ b/lib/bundler/vendor/thor.rb @@ -23,6 +23,7 @@ class Thor # ==== Parameters # usage # description + # options # def desc(usage, description, options={}) if options[:for] @@ -30,7 +31,7 @@ class Thor task.usage = usage if usage task.description = description if description else - @usage, @desc = usage, description + @usage, @desc, @hide = usage, description, options[:hide] || false end end @@ -135,6 +136,7 @@ class Thor # def start(original_args=ARGV, config={}) @@original_args = original_args + super do |given_args| meth = given_args.first.to_s @@ -154,7 +156,7 @@ class Thor args, opts = given_args, {} end - task ||= Thor::Task::Dynamic.new(meth) + task ||= Thor::DynamicTask.new(meth) trailing = args[Range.new(arguments.size, -1)] new(args, opts, config).invoke(task, trailing || []) end @@ -204,11 +206,12 @@ class Thor # Returns tasks ready to be printed. def printable_tasks(all = true, subcommand = false) (all ? all_tasks : tasks).map do |_, task| + next if task.hidden? item = [] item << banner(task, false, subcommand) item << (task.description ? "# #{task.description.gsub(/\s+/m,' ')}" : "") item - end + end.compact end def subcommands @@ -239,8 +242,9 @@ class Thor def create_task(meth) #:nodoc: if @usage && @desc - tasks[meth.to_s] = Thor::Task.new(meth, @desc, @long_desc, @usage, method_options) - @usage, @desc, @long_desc, @method_options = nil + base_class = @hide ? Thor::HiddenTask : Thor::Task + tasks[meth.to_s] = base_class.new(meth, @desc, @long_desc, @usage, method_options) + @usage, @desc, @long_desc, @method_options, @hide = nil true elsif self.all_tasks[meth.to_s] || meth.to_sym == :method_missing true diff --git a/lib/bundler/vendor/thor/base.rb b/lib/bundler/vendor/thor/base.rb index 08a234d1..9798cb7e 100644 --- a/lib/bundler/vendor/thor/base.rb +++ b/lib/bundler/vendor/thor/base.rb @@ -336,6 +336,7 @@ class Thor def no_tasks @no_tasks = true yield + ensure @no_tasks = false end diff --git a/lib/bundler/vendor/thor/invocation.rb b/lib/bundler/vendor/thor/invocation.rb index 4a081839..73c8bb5d 100644 --- a/lib/bundler/vendor/thor/invocation.rb +++ b/lib/bundler/vendor/thor/invocation.rb @@ -156,7 +156,7 @@ class Thor raise "Expected Thor class, got #{klass}" unless klass <= Thor::Base task ||= klass.default_task if klass.respond_to?(:default_task) - task = klass.all_tasks[task.to_s] || Thor::Task::Dynamic.new(task) if task && !task.is_a?(Thor::Task) + task = klass.all_tasks[task.to_s] || Thor::DynamicTask.new(task) if task && !task.is_a?(Thor::Task) task end diff --git a/lib/bundler/vendor/thor/task.rb b/lib/bundler/vendor/thor/task.rb index 2576c752..a4355831 100644 --- a/lib/bundler/vendor/thor/task.rb +++ b/lib/bundler/vendor/thor/task.rb @@ -2,21 +2,6 @@ class Thor class Task < Struct.new(:name, :description, :long_description, :usage, :options) FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/ - # A dynamic task that handles method missing scenarios. - class Dynamic < Task - def initialize(name, options=nil) - super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options) - end - - def run(instance, args=[]) - if (instance.methods & [name.to_s, name.to_sym]).empty? - super - else - instance.class.handle_no_task_error(name) - end - end - end - def initialize(name, description, long_description, usage, options=nil) super(name.to_s, description, long_description, usage, options || {}) end @@ -26,6 +11,10 @@ class Thor self.options = other.options.dup if other.options end + def hidden? + false + end + # By default, a task invokes a method in the thor class. You can change this # implementation to create custom tasks. def run(instance, args=[]) @@ -42,9 +31,8 @@ class Thor # Returns the formatted usage by injecting given required arguments # and required options into the given usage. def formatted_usage(klass, namespace = true, subcommand = false) - namespace = klass.namespace unless namespace == false - if namespace + namespace = klass.namespace formatted = "#{namespace.gsub(/^(default)/,'')}:" formatted.sub!(/.$/, ' ') if subcommand end @@ -67,39 +55,60 @@ class Thor formatted.strip end - protected + protected - def not_debugging?(instance) - !(instance.class.respond_to?(:debugging) && instance.class.debugging) - end + def not_debugging?(instance) + !(instance.class.respond_to?(:debugging) && instance.class.debugging) + end - def required_options - @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ") - end + def required_options + @required_options ||= options.map{ |_, o| o.usage if o.required? }.compact.sort.join(" ") + end - # Given a target, checks if this class name is not a private/protected method. - def public_method?(instance) #:nodoc: - collection = instance.private_methods + instance.protected_methods - (collection & [name.to_s, name.to_sym]).empty? - end + # Given a target, checks if this class name is not a private/protected method. + def public_method?(instance) #:nodoc: + collection = instance.private_methods + instance.protected_methods + (collection & [name.to_s, name.to_sym]).empty? + end - def sans_backtrace(backtrace, caller) #:nodoc: - saned = backtrace.reject { |frame| frame =~ FILE_REGEXP } - saned -= caller - end + def sans_backtrace(backtrace, caller) #:nodoc: + saned = backtrace.reject { |frame| frame =~ FILE_REGEXP } + saned -= caller + end - 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 + 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 - def handle_no_method_error?(instance, error, caller) - not_debugging?(instance) && - error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ - end + def handle_no_method_error?(instance, error, caller) + not_debugging?(instance) && + error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ + end + end + # A task that is hidden in help messages but still invocable. + class HiddenTask < Task + def hidden? + true + end + end + + # A dynamic task that handles method missing scenarios. + class DynamicTask < Task + def initialize(name, options=nil) + super(name.to_s, "A dynamically-generated task", name.to_s, name.to_s, options) + end + + def run(instance, args=[]) + if (instance.methods & [name.to_s, name.to_sym]).empty? + super + else + instance.class.handle_no_task_error(name) + end + end end end \ No newline at end of file diff --git a/lib/bundler/vendor/thor/version.rb b/lib/bundler/vendor/thor/version.rb index aba08b72..503cd65b 100644 --- a/lib/bundler/vendor/thor/version.rb +++ b/lib/bundler/vendor/thor/version.rb @@ -1,3 +1,3 @@ class Thor - VERSION = "0.13.7".freeze + VERSION = "0.13.8".freeze end -- cgit v1.2.3