diff options
author | Benoit Tigeot <benoit@hopsandfork.com> | 2018-02-25 18:25:55 +0100 |
---|---|---|
committer | Benoit Tigeot <benoit@hopsandfork.com> | 2018-02-28 22:32:34 +0100 |
commit | c6d928f3cae28e3b531d3cc4bcde2ddca0323f11 (patch) | |
tree | 3dd6a24b71abb5b9902a462c70d2d44aef94e099 /railties/lib | |
parent | 39d2cde65919729ec1ca3663d7872adf8036fd58 (diff) | |
download | rails-c6d928f3cae28e3b531d3cc4bcde2ddca0323f11.tar.gz rails-c6d928f3cae28e3b531d3cc4bcde2ddca0323f11.tar.bz2 rails-c6d928f3cae28e3b531d3cc4bcde2ddca0323f11.zip |
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 | {}
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/routes/routes_command.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/railties/lib/rails/commands/routes/routes_command.rb b/railties/lib/rails/commands/routes/routes_command.rb index c4fd6c7eb5..c4f3717095 100644 --- a/railties/lib/rails/commands/routes/routes_command.rb +++ b/railties/lib/rails/commands/routes/routes_command.rb @@ -7,12 +7,14 @@ module Rails 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: "Turn on expanded format mode." no_commands do def help say "Usage: Print out all defined routes in match order, with names." say "" say "Target specific controller with -c option, or grep routes using -g option" + say "Use expanded format with --expanded option" say "" end end @@ -24,7 +26,11 @@ module Rails all_routes = Rails.application.routes.routes inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) - say inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter) + if options.has_key?("expanded_format") + say inspector.format(ActionDispatch::Routing::ConsoleFormatter::Expanded.new, routes_filter) + else + say inspector.format(ActionDispatch::Routing::ConsoleFormatter::Sheet.new, routes_filter) + end end private |