lib/thor/command.rb in thor-0.19.1 vs lib/thor/command.rb in thor-0.19.2

- old
+ new

@@ -1,11 +1,11 @@ class Thor - class Command < Struct.new(:name, :description, :long_description, :usage, :options) + class Command < Struct.new(:name, :description, :long_description, :usage, :options, :disable_class_options) FILE_REGEXP = /^#{Regexp.escape(File.dirname(__FILE__))}/ - def initialize(name, description, long_description, usage, options = nil) - super(name.to_s, description, long_description, usage, options || {}) + def initialize(name, description, long_description, usage, options = nil, disable_class_options = false) + super(name.to_s, description, long_description, usage, options || {}, disable_class_options) end def initialize_copy(other) #:nodoc: super(other) self.options = other.options.dup if other.options @@ -31,11 +31,11 @@ instance.class.handle_no_command_error(name) end rescue ArgumentError => e handle_argument_error?(instance, e, caller) ? instance.class.handle_argument_error(self, e, args, arity) : (raise e) rescue NoMethodError => e - handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (fail e) + handle_no_method_error?(instance, e, caller) ? instance.class.handle_no_command_error(name) : (raise e) end # Returns the formatted usage by injecting given required arguments # and required options into the given usage. def formatted_usage(klass, namespace = true, subcommand = false) @@ -48,11 +48,11 @@ 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(" ") + match << " " << klass.arguments.map(&:usage).compact.join(" ") end else usage.to_s end @@ -86,11 +86,11 @@ methods = instance.public_methods(false) + instance.private_methods(false) + instance.protected_methods(false) !(methods & [name.to_s, name.to_sym]).empty? end def sans_backtrace(backtrace, caller) #:nodoc: - saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ /^kernel\// && RUBY_ENGINE =~ /rbx/) } + saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ %r{^kernel/} && RUBY_ENGINE =~ /rbx/) } saned - caller end def handle_argument_error?(instance, error, caller) not_debugging?(instance) && (error.message =~ /wrong number of arguments/ || error.message =~ /given \d*, expected \d*/) && begin @@ -103,19 +103,19 @@ def handle_no_method_error?(instance, error, caller) not_debugging?(instance) && error.message =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ end end - Task = Command # rubocop:disable ConstantName + Task = Command # A command that is hidden in help messages but still invocable. class HiddenCommand < Command def hidden? true end end - HiddenTask = HiddenCommand # rubocop:disable ConstantName + HiddenTask = HiddenCommand # A dynamic command that handles method missing scenarios. class DynamicCommand < Command def initialize(name, options = nil) super(name.to_s, "A dynamically-generated command", name.to_s, name.to_s, options) @@ -127,7 +127,7 @@ else instance.class.handle_no_command_error(name) end end end - DynamicTask = DynamicCommand # rubocop:disable ConstantName + DynamicTask = DynamicCommand end