Class: Bundler::Thor::Command
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Subclasses:
|
|
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Struct
|
|
Instance Chain:
self,
Struct
|
|
Inherits: |
Struct
|
Defined in: | lib/bundler/vendor/thor/lib/thor/command.rb |
Constant Summary
-
FILE_REGEXP =
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 3/^#{Regexp.escape(File.dirname(__FILE__))}/
Class Method Summary
Instance Attribute Summary
- #ancestor_name rw
- #description rw
- #hidden? ⇒ Boolean readonly
- #long_description rw
- #name rw
- #options rw
- #usage rw
Instance Method Summary
-
#formatted_usage(klass, namespace = true, subcommand = false)
Returns the formatted usage by injecting given required arguments and required options into the given usage.
-
#run(instance, args = [])
By default, a command invokes a method in the thor class.
- #handle_argument_error?(instance, error, caller) ⇒ Boolean protected
- #handle_no_method_error?(instance, error, caller) ⇒ Boolean protected
- #local_method?(instance, name) ⇒ Boolean protected
- #not_debugging?(instance) ⇒ Boolean protected
- #private_method?(instance) ⇒ Boolean protected
-
#required_arguments_for(klass, usage)
protected
Add usage with required arguments.
- #required_options protected
- #initialize_copy(other) Internal use only
-
#public_method?(instance) ⇒ Boolean
protected
Internal use only
Given a target, checks if this class name is a public method.
- #sans_backtrace(backtrace, caller) protected Internal use only
Constructor Details
.new(name, description, long_description, usage, options = nil) ⇒ Command
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 5
def initialize(name, description, long_description, usage, = nil) super(name.to_s, description, long_description, usage, || {}) end
Instance Attribute Details
#ancestor_name (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
#description (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
#long_description (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
#name (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
#options (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
#usage (rw)
[ GitHub ]# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 2
class Command < Struct.new(:name, :description, :long_description, :usage, :, :ancestor_name)
Instance Method Details
#formatted_usage(klass, namespace = true, subcommand = false)
Returns the formatted usage by injecting given required arguments and required options into the given usage.
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 41
def formatted_usage(klass, namespace = true, subcommand = false) if ancestor_name formatted = "#{ancestor_name} ".dup # add space elsif namespace namespace = klass.namespace formatted = "#{namespace.gsub(/^(default)/, '')}:".dup end formatted ||= "#{klass.namespace.split(':').last} ".dup if subcommand formatted ||= "".dup Array(usage).map do |specific_usage| formatted_specific_usage = formatted formatted_specific_usage += required_arguments_for(klass, specific_usage) # Add required options formatted_specific_usage += " #{}" # Strip and go! formatted_specific_usage.strip end.join("\n") end
#handle_argument_error?(instance, error, caller) ⇒ Boolean
(protected)
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 105
def handle_argument_error?(instance, error, caller) not_debugging?(instance) && (error. =~ /wrong number of arguments/ || error. =~ /given \d*, expected \d*/) && begin saned = sans_backtrace(error.backtrace, caller) saned.empty? || saned.size == 1 end end
#handle_no_method_error?(instance, error, caller) ⇒ Boolean
(protected)
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 112
def handle_no_method_error?(instance, error, caller) not_debugging?(instance) && error. =~ /^undefined method `#{name}' for #{Regexp.escape(instance.to_s)}$/ end
#initialize_copy(other)
This method is for internal use only.
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 9
def initialize_copy(other) #:nodoc: super(other) self. = other. .dup if other. end
#local_method?(instance, name) ⇒ Boolean
(protected)
#not_debugging?(instance) ⇒ Boolean
(protected)
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 78
def not_debugging?(instance) !(instance.class.respond_to?(:debugging) && instance.class.debugging) end
#private_method?(instance) ⇒ Boolean
(protected)
#public_method?(instance) ⇒ Boolean
(protected)
This method is for internal use only.
Given a target, checks if this class name is a public method.
#required_arguments_for(klass, usage) (protected)
Add usage with required arguments
#required_options (protected)
[ GitHub ]#run(instance, args = [])
By default, a command invokes a method in the thor class. You can change this implementation to create custom commands.
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 20
def run(instance, args = []) arity = nil if private_method?(instance) instance.class.handle_no_command_error(name) elsif public_method?(instance) arity = instance.method(name).arity instance.__send__(name, *args) elsif local_method?(instance, :method_missing) instance.__send__(:method_missing, name.to_sym, *args) else 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) : (raise e) end
#sans_backtrace(backtrace, caller) (protected)
This method is for internal use only.
[ GitHub ]
# File 'lib/bundler/vendor/thor/lib/thor/command.rb', line 100
def sans_backtrace(backtrace, caller) #:nodoc: saned = backtrace.reject { |frame| frame =~ FILE_REGEXP || (frame =~ /\.java:/ && RUBY_PLATFORM =~ /java/) || (frame =~ %r{^kernel/} && RUBY_ENGINE =~ /rbx/) } saned - caller end