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

Add "rails routes --expanded" mode #32130

Merged
merged 1 commit into from Feb 28, 2018

Conversation

Projects
None yet
7 participants
@benoittgt
Contributor

benoittgt commented Feb 27, 2018

Summary

When using rails routes with small terminal or complicated routes it can be very difficult to understand where a specific element is, especially when using header. psql had the same issue, that's why they created "expanded mode" long time ago that you can
switch using \x or by starting psql with

-x
--expanded

    Turn on the expanded table formatting mode. This is equivalent to the \x command.

The output is similar to one implemented here for rails routes:

db_user-# \du
List of roles
-[ RECORD 1 ]----------------------------------------------
Role name  | super
Attributes | Superuser, Create role, Create DB
Member of  | {}
-[ RECORD 2 ]----------------------------------------------
Role name  | role
Attributes | Superuser, Create role, Create DB, Replication
Member of  | {}

Here is an output expanded mode (I removed active storage routes):

$ rails routes --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new
--[ Route 3 ]------------------------------------------------------------
Prefix            | blog
Verb              |
URI               | /blog
Controller#Action | Blog::Engine

[ Routes for Blog::Engine ]
--[ Route 1 ]------------------------------------------------------------
Prefix            | cart
Verb              | GET
URI               | /cart(.:format)
Controller#Action | cart#show

Other Information

  • I didn't add an entry to changelog because it seems too early for me. Also, I didn't know where you want this to be targeted if it was approved.
  • App used to display routes
@rails-bot

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot Feb 27, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @georgeclaghorn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

rails-bot commented Feb 27, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @georgeclaghorn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@jaredbeck

This comment has been minimized.

Show comment
Hide comment
@jaredbeck

jaredbeck Feb 27, 2018

Contributor

Good idea Benoit, this will be helpful. It'll be harder to grep this format, but we can't have everything. :)

Contributor

jaredbeck commented Feb 27, 2018

Good idea Benoit, this will be helpful. It'll be harder to grep this format, but we can't have everything. :)

@benoittgt

This comment has been minimized.

Show comment
Hide comment
@benoittgt

benoittgt Feb 27, 2018

Contributor

@jaredbeck you can still use '-c controller' or '-g pattern'

rails routes -g high --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new
Contributor

benoittgt commented Feb 27, 2018

@jaredbeck you can still use '-c controller' or '-g pattern'

rails routes -g high --expanded
--[ Route 1 ]------------------------------------------------------------
Prefix            | high_scores
Verb              | GET
URI               | /high_scores(.:format)
Controller#Action | high_scores#index
--[ Route 2 ]------------------------------------------------------------
Prefix            | new_high_score
Verb              | GET
URI               | /high_scores/new(.:format)
Controller#Action | high_scores#new
@jaredbeck

This comment has been minimized.

Show comment
Hide comment
@jaredbeck

jaredbeck Feb 27, 2018

Contributor

@jaredbeck you can still use '-c controller' or '-g pattern'

Awesome. I had no idea about either of those, thanks.

Contributor

jaredbeck commented Feb 27, 2018

@jaredbeck you can still use '-c controller' or '-g pattern'

Awesome. I had no idea about either of those, thanks.

@rafaelfranca

Looks good to me. Can you add a CHANGELOG entry to the railties changelog?

Show outdated Hide outdated railties/lib/rails/commands/routes/routes_command.rb Outdated
@benoittgt

This comment has been minimized.

Show comment
Hide comment
@benoittgt

benoittgt Feb 28, 2018

Contributor

When it's good I can squash. Thanks to all of you for the reviews. 🤙🏻

Contributor

benoittgt commented Feb 28, 2018

When it's good I can squash. Thanks to all of you for the reviews. 🤙🏻

Add --expanded option to "rails routes"
When using rails routes with small terminal or complicated routes it can be
very difficult to understand where is the element listed in header. psql
had the same issue, that's why they created "expanded mode" you can
switch using `\x` or by starting psql with
```
-x
--expanded

    Turn on the expanded table formatting mode. This is equivalent to the \x command.
```
The output is similar to one implemented here for rails routes:

db_user-# \du
List of roles
-[ RECORD 1 ]----------------------------------------------
Role name  | super
Attributes | Superuser, Create role, Create DB
Member of  | {}
-[ RECORD 2 ]----------------------------------------------
Role name  | role
Attributes | Superuser, Create role, Create DB, Replication
Member of  | {}
@benoittgt

This comment has been minimized.

Show comment
Hide comment
@benoittgt

benoittgt Feb 28, 2018

Contributor

Squashed 🎉

Contributor

benoittgt commented Feb 28, 2018

Squashed 🎉

@rafaelfranca rafaelfranca merged commit c9fa561 into rails:master Feb 28, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
codeclimate All good!
Details

@benoittgt benoittgt deleted the benoittgt:rake-routes-compact-mode branch Mar 1, 2018

@Schwad

This comment has been minimized.

Show comment
Hide comment
@Schwad

Schwad Mar 1, 2018

Contributor

Really excited for this feature, thank you so much for your work. 🎆

Contributor

Schwad commented Mar 1, 2018

Really excited for this feature, thank you so much for your work. 🎆

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Mar 5, 2018

bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Mar 13, 2018

Introduce `ActionDispatch::Routing::ConsoleFormatter::Base`
- Create `Base` and inherit `Sheet` and `Expanded` in order to
- prevent code duplication.
  - Remove trailing "\n" for components of `Expanded`.
  - There is no need for `Expanded#header` to return `@buffer` so return `nil` instead.

- Change `no_routes` message "No routes were found for this controller"
  since if use `-g`, it sounds incorrect.
  - Display `No routes were found for this controller.` if apply `-c`.
  - Display `No routes were found for this grep pattern.` if apply `-g`.

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