rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.11k stars 552 forks source link

Correctly identify hyphenated and alias command names #878

Open takmar opened 3 months ago

takmar commented 3 months ago

Fixes https://github.com/rails/thor/issues/868

Problem: After version 1.3.0, invoking commands with hyphenated and alias names does not function as expected.

Given a Thor class definition as follows:

Copy code
class Test < Thor
  desc "foo-bar", "an example task"
  def foo_bar
    puts "I'm a thor task!"
  end

  map "fb" => :foo_bar 
end

Attempting to invoke the command with a hyphenated and the alias command:

% bundle exec thor test:foo-bar
% bundle exec thor test:FB

Results in a failure to execute the specified command, even though the help output correctly lists the command and its alias.

This PR addresses the issue by implementing a fix in the find_class_and_command_by_namespace method, ensuring that it correctly identifies both hyphenated command names and their aliases.

naomichi-y commented 3 months ago

It worked correctly 👍

bastelfreak commented 1 week ago

hey people, any chance this can get reviewed and merged? This fixes CI errors in one of my projects, https://github.com/voxpupuli/modulesync.