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

Offer alternatives if rake task not found #19

Closed
wants to merge 2 commits into from
Closed

Offer alternatives if rake task not found #19

wants to merge 2 commits into from

Conversation

djberg96
Copy link
Contributor

If your rake task name happens to be wrong on the command line, the output is not that helpful. Next thing you know you're grepping through rake -T output.

This pull request does some simple matching to offer alternatives if the name you specified isn't found. For example, if you have tasks "foobar" and "foobaz", but accidentally type "rake foo" on the command line, you'll see this:

Don't know how to build task 'foo'. Did you mean one of these?

  foobar
  foobaz

@jrafanie
Copy link
Contributor

❤️ This reminds me of rails/rails#15497. It would be nice if it handled typos of fobar/foobr but this is much simpler and much better than what we have right now. Note, I often typo destroy as destory so I'm partial to that rails PR. Nevertheless, this is awesome!

def build_task_fail(task_name)
msg = "Don't know how to build task '#{task_name}'"
if task_name.size > 1
matches = @tasks.keys.find_all{ |e| e =~ /#{task_name}/i }
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably want /#{Regexp.escape task_name}/, unless no Regexp special characters can ever occur in a task name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've never seen one in the wild, but it's possible I suppose.

@hsbt
Copy link
Member

hsbt commented Jul 30, 2016

I hope to implement this feature with did_you_mean gem.

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

Successfully merging this pull request may close these issues.

4 participants