From c6d928f3cae28e3b531d3cc4bcde2ddca0323f11 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Sun, 25 Feb 2018 18:25:55 +0100 Subject: 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 | {} --- railties/lib/rails/commands/routes/routes_command.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/lib/rails/commands/routes') 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 -- cgit v1.2.3