Skip to content

Commit

Permalink
Fix find_class_and_command_by_namespace to correctly identify hyphena…
Browse files Browse the repository at this point in the history
…ted and alias command names
  • Loading branch information
takmar committed Mar 22, 2024
1 parent 7b0ebc4 commit 40ab451
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/thor/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions spec/util_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40ab451

Please sign in to comment.