diff --git a/lib/thor/util.rb b/lib/thor/util.rb index 8a2ccef1..6fa0b3d9 100644 --- a/lib/thor/util.rb +++ b/lib/thor/util.rb @@ -133,7 +133,7 @@ def find_class_and_command_by_namespace(namespace, fallback = true) *pieces, command = namespace.split(":") namespace = pieces.join(":") namespace = "default" if namespace.empty? - klass = Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.commands.keys.include?(command) } + klass = Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.command_exists?(command) } end unless klass # look for a Thor::Group with the right name klass = Thor::Util.find_by_namespace(namespace) diff --git a/spec/util_spec.rb b/spec/util_spec.rb index 80665edc..54cc051b 100644 --- a/spec/util_spec.rb +++ b/spec/util_spec.rb @@ -114,6 +114,14 @@ def self.clear_user_home! expect(Thor::Util.find_class_and_command_by_namespace("fruits:apple")).to eq([Apple, "apple"]) expect(Thor::Util.find_class_and_command_by_namespace("fruits:pear")).to eq([Pear, "pear"]) end + + it "returns correct Thor class and the command name with hypen when shared namespaces" do + expect(Thor::Util.find_class_and_command_by_namespace("fruits:rotten-apple")).to eq([Apple, "rotten-apple"]) + end + + it "returns correct Thor class and the associated alias command name when shared namespaces" do + expect(Thor::Util.find_class_and_command_by_namespace("fruits:ra")).to eq([Apple, "ra"]) + end end describe "#thor_classes_in" do