[Feature Idea] Adding a Generator for Thor Commands

While Rails has great support for adding Rake tasks there is currently no information on how to add Thor commands, despite Thor playing an active role internally. I find Thor commands to be better for handling more sophisticated interaction from the user and they’re great for testing. There already seems to be solid conventions in place for Rails/Thor commands for either engines or applications however, this is currently undocumented.

I just wrote an article describing how an app or engine author can add their own namespaced Commands here: http://www.joshklina.com/posts/adding-thor-commands-to-rails

I’d be happy to create a patch that adds a Command generator and write up documentation if you folks would be interested.

Great blog post! :clap:

I think the answer you’re looking for is: yet. We want apps to be able to write full fledged commands for all the reasons you mention, we just haven’t finished it up… yet.

That’s why there’s no documentation and the reason for the rough edge you mention at the end of your post.

Here’s where you and others can help now:

  • Better load paths and loading: helps with the issue you identified. Must work for our internal commands as well as apps.

  • Command dependencies: attaching a command to run after e.g. db:migrate (so we can move our Rake tasks to Rails commands, plus apps can write commands that hook in after db:migrate etc.)

  • Making commands conductable: finally fulfilling the 13+ year dream of https://github.com/rails/conductor come true. Should be great for people new to Rails too!

Later, we’ll need the command generator, like you mentioned, and proper documentation.

Again, appreciate the write up! Since you’re already eager to make this work in your apps, you’d be a good fit to help out here.

So: looking forward to your issues/pull requests :heart:

Thanks for the roadmap! I’ll go ahead and see if I can start chipping away at this!

Cheers, Josh

Happy to hear it!

Hi Kasper,

I started diving into this and added a way to incorporate a Rails app into the load path for commands. The Railties test suite seems to pass, but I wanted to get some feedback before submitting a pull request.



Pull requests are made to get feedback, so if you’ve got the code why not just open one? :smiley:

Feel free to use “r? @kaspth” to assign it to me.

Couldn’t figure out how to assign it to you specifically, but I created the pull request here:


Thanks again for the help!