Skip to content

Commit 3821657

Browse files
committed
Fix find_class_and_command_by_namespace to correctly identify hyphenated and alias command names
1 parent 871d132 commit 3821657

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

lib/thor/util.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def find_class_and_command_by_namespace(namespace, fallback = true)
133133
*pieces, command = namespace.split(":")
134134
namespace = pieces.join(":")
135135
namespace = "default" if namespace.empty?
136-
klass = Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.commands.keys.include?(command) }
136+
klass = Thor::Base.subclasses.detect { |thor| thor.namespace == namespace && thor.command_exists?(command) }
137137
end
138138
unless klass # look for a Thor::Group with the right name
139139
klass = Thor::Util.find_by_namespace(namespace)

spec/util_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ def self.clear_user_home!
114114
expect(Thor::Util.find_class_and_command_by_namespace("fruits:apple")).to eq([Apple, "apple"])
115115
expect(Thor::Util.find_class_and_command_by_namespace("fruits:pear")).to eq([Pear, "pear"])
116116
end
117+
118+
it "returns correct Thor class and the command name with hypen when shared namespaces" do
119+
expect(Thor::Util.find_class_and_command_by_namespace("fruits:rotten-apple")).to eq([Apple, "rotten-apple"])
120+
end
121+
122+
it "returns correct Thor class and the associated alias command name when shared namespaces" do
123+
expect(Thor::Util.find_class_and_command_by_namespace("fruits:ra")).to eq([Apple, "ra"])
124+
end
117125
end
118126

119127
describe "#thor_classes_in" do

0 commit comments

Comments
 (0)