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

[close #18878] Proxy `rake` tasks through `rails` #21012

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@schneems
Member

schneems commented Jul 24, 2015

Currently when you accidentally run $ bin/rails db:migrate you got an error message:

Error: Command 'db:migrate' not recognized
Did you mean: `$ rake db:migrate` ?

After this change you'll still get an error message, but it will also run the command:

$ be rails routes
Error: Command 'routes' not a valid rails command
Running: `$ bin/rake routes` instead

                  Prefix Verb     URI Pattern                                           Controller#Action
                teaspoon          /jstest                                               Teaspoon::Engine
           users_sign_in GET      /users/sign_in(.:format)                              redirect(301, /users/auth/github)
           users_sign_up GET      /users/sign_up(.:format)                              redirect(301, /users/auth/github)
        new_user_session GET      /users/sign_in(.:format)                              devise/sessions#new
            user_session POST     /users/sign_in(.:format)                              devise/sessions#create
# ...

I highly recommend that we keep the warning message. Without it running $ rails --help won't show all available commands and rails db:migrate would be a touch too magical for my tastes. If we want to switch over documentation so that some commands such as rails test work out of the box, we should whitelist them. The alternative would be we add the $ rake -T output to $ rails --help and that would get pretty messy.

Thanks to @repinel for the tip on speeding up the rake check

[close #18878] Proxy `rake` tasks through `rails`
Currently when you accidentally run `$ bin/rails db:migrate` you got an error message:

```
Error: Command 'db:migrate' not recognized
Did you mean: `$ rake db:migrate` ?
```

After this change you'll still get an error message, but it will also run the command:

```
$ be rails routes
Error: Command 'routes' not a valid rails command
Running: `$ bin/rake routes` instead

                  Prefix Verb     URI Pattern                                           Controller#Action
                teaspoon          /jstest                                               Teaspoon::Engine
           users_sign_in GET      /users/sign_in(.:format)                              redirect(301, /users/auth/github)
           users_sign_up GET      /users/sign_up(.:format)                              redirect(301, /users/auth/github)
        new_user_session GET      /users/sign_in(.:format)                              devise/sessions#new
            user_session POST     /users/sign_in(.:format)                              devise/sessions#create
# ...
```

I highly recommend that we keep the warning message. Without it running `$ rails --help` won't show all available commands and `rails db:migrate` would be a touch too magical for my tastes. If we want to switch over documentation so that some commands such as `rails test` work out of the box, we should whitelist them. The alternative would be we add the `$ rake -T` output to `$ rails --help` and that would get pretty messy. 



Thanks to @repinel for the tip on speeding up the rake check
@repinel

This comment has been minimized.

Show comment
Hide comment
@repinel

repinel Jul 24, 2015

Member

Cool ❤️

Member

repinel commented Jul 24, 2015

Cool ❤️

Rails.application.load_tasks
if Rake::Task.task_defined?(command)
puts "Running: `$ bin/rake #{command}` instead\n\n"
system("bin/rake #{command}")

This comment has been minimized.

@simi

simi Jul 30, 2015

Contributor

Is there any chance to try invoke rake task (Rake::Task["my:task"].invoke) instead of using system?

@simi

simi Jul 30, 2015

Contributor

Is there any chance to try invoke rake task (Rake::Task["my:task"].invoke) instead of using system?

This comment has been minimized.

@schneems

schneems Jul 31, 2015

Member

We talked about that in DHH's original issue, that should work fine.

@schneems

schneems Jul 31, 2015

Member

We talked about that in DHH's original issue, that should work fine.

@arthurnn

This comment has been minimized.

Show comment
Hide comment
@arthurnn

arthurnn Oct 5, 2015

Member

this is cool and weird . lol ...
What I mean is, How so I get an error and the command still runs. Rails should not be THAT IMO.
I think we have an issue to convert the rake tasks to rails commands instead. I think this would be a good start. So we could map the existent rake tasks to Rails commands.
That would be better than handling the error case i guess.

Member

arthurnn commented Oct 5, 2015

this is cool and weird . lol ...
What I mean is, How so I get an error and the command still runs. Rails should not be THAT IMO.
I think we have an issue to convert the rake tasks to rails commands instead. I think this would be a good start. So we could map the existent rake tasks to Rails commands.
That would be better than handling the error case i guess.

@sgrif

This comment has been minimized.

Show comment
Hide comment
@sgrif

sgrif Oct 20, 2015

Member

This doesn't seem to be the right approach anymore, given that we've decided to have rails any_rake_task be valid in Rails 5.

Member

sgrif commented Oct 20, 2015

This doesn't seem to be the right approach anymore, given that we've decided to have rails any_rake_task be valid in Rails 5.

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