Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly identify hyphenated and alias command names #878

Merged
merged 2 commits into from
Aug 28, 2024

Conversation

takmar
Copy link
Contributor

@takmar takmar commented Mar 22, 2024

Fixes #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:

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

  map "fb" => :foo_bar 
end

Each command results in the following.

% thor test:foo_bar
I'm a thor task!
% thor test:foo-bar
Commands:
  thor test:foo-bar         # an example task
  thor test:help [COMMAND]  # Describe available commands or one specific command
% thor test:fb
Commands:
  thor test:foo-bar         # an example task
  thor test:help [COMMAND]  # Describe available commands or one specific command

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
Copy link

It worked correctly 👍

bastelfreak added a commit to bastelfreak/modulesync that referenced this pull request May 17, 2024
With thor 1.3.1 we've two failing tests:

```
Failing Scenarios:
cucumber features/execute.feature:36 # Scenario: Show fail-fast default value in help
cucumber features/execute.feature:44 # Scenario: Override fail-fast default value using config file
```

as a workaround to get CI green again we'r pinning to 1.3.0. I think the
bug is fixed in rails/thor#878 but not yet
released.
@bastelfreak
Copy link

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

lib/thor.rb Outdated
#
# ==== Returns
# Boolean:: +true+ if the command exists, +false+ otherwise.
def command_exists?(command_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this method in the public API? Should we :nodoc: it instead? I don't think we have a need to expose this to users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for reviewing. I added :nodoc:.

@takmar takmar force-pushed the fix/find-class-and-command-name branch from 40ab451 to 3821657 Compare August 24, 2024 12:38
@rafaelfranca rafaelfranca merged commit f2e243d into rails:main Aug 28, 2024
8 checks passed
@bastelfreak
Copy link

@rafaelfranca thanks for the merge! Would it be possible to make a new release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commands that contain hyphens cannot be executed
4 participants