Skip to content

Commit

Permalink
check commands to find the correct class when multiple classes have t…
Browse files Browse the repository at this point in the history
…he same namespace
  • Loading branch information
Gerst20051 committed Aug 17, 2021
1 parent efe79b5 commit f9499ef
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/thor/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class << self
# ==== Parameters
# namespace<String>:: The namespace to search for.
#
def find_by_namespace(namespace)
def find_by_namespace(namespace, command = nil)
namespace = "default#{namespace}" if namespace.empty? || namespace =~ /^:/
Thor::Base.subclasses.detect { |klass| klass.namespace == namespace }
Thor::Base.subclasses.detect { |klass| klass.namespace == namespace and command.nil? || klass.commands.keys.include?(command) }
end

# Receives a constant and converts it to a Thor namespace. Since Thor
Expand Down Expand Up @@ -132,7 +132,8 @@ def find_class_and_command_by_namespace(namespace, fallback = true)
if namespace.include?(":") # look for a namespaced command
pieces = namespace.split(":")
command = pieces.pop
klass = Thor::Util.find_by_namespace(pieces.join(":"))
klass = Thor::Util.find_by_namespace(pieces.join(":"), command)
klass ||= Thor::Util.find_by_namespace(pieces.join(":"))
end
unless klass # look for a Thor::Group with the right name
klass = Thor::Util.find_by_namespace(namespace)
Expand Down

0 comments on commit f9499ef

Please sign in to comment.