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

Add "rails routes --expanded" mode #32130

Merged
merged 1 commit into from Feb 28, 2018

Conversation

@benoittgt
Copy link
Contributor

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

@rails-bot 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
Copy link
Contributor

@jaredbeck 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
Copy link
Contributor Author

@benoittgt 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
Copy link
Contributor

@jaredbeck 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.

Copy link
Member

@rafaelfranca rafaelfranca left a comment

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

railties/lib/rails/commands/routes/routes_command.rb Outdated
@@ -7,12 +7,14 @@ module Command
class RoutesCommand < Base # :nodoc:
class_option :controller, aliases: "-c", type: :string, desc: "Specifies the controller."
class_option :grep_pattern, aliases: "-g", type: :string, desc: "Specifies grep pattern."
class_option :expanded_format, aliases: "--expanded", type: :string, desc: "Specifies grep pattern."

This comment has been minimized.

@yskkin

yskkin Feb 28, 2018
Contributor

I believe that desc should be rewrited.

This comment has been minimized.

@benoittgt

benoittgt Feb 28, 2018
Author Contributor

ouppps correct

@benoittgt
Copy link
Contributor Author

@benoittgt benoittgt commented Feb 28, 2018

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

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 benoittgt force-pushed the benoittgt:rake-routes-compact-mode branch to c6d928f Feb 28, 2018
@benoittgt
Copy link
Contributor Author

@benoittgt benoittgt commented Feb 28, 2018

Squashed 🎉

@rafaelfranca rafaelfranca merged commit c9fa561 into rails:master Feb 28, 2018
1 of 2 checks passed
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
Copy link
Contributor

@Schwad 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
…--expanded`

In order to get width of console use `IO::console_size`,
See https://ruby-doc.org/stdlib-2.4.1/libdoc/io/console/rdoc/IO.html#method-c-console_size

Related to rails#32130
bogdanvlviv added a commit to bogdanvlviv/rails that referenced this pull request Mar 13, 2018
- 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants
You can’t perform that action at this time.