From 6629d51a2756fadf961bb09df20579cacfef2c8e Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 13 Mar 2018 20:51:29 +0100 Subject: Rely on Rails::Command's help output. We end up with: ``` Usage: bin/rails routes [options] Options: -c, [--controller=CONTROLLER] # Filter by a specific controller, e.g. PostsController or Admin::PostsController. -g, [--grep=GREP] # Grep routes by a specific pattern. -E, [--expanded], [--no-expanded] # Print routes expanded vertically with parts explained. ``` which does miss the bit about routes being printed in order. Also: * Renames options to ease help output readability, then clarifies each option. * Fixes a bunch of indentation. --- railties/lib/rails/commands/routes/routes_command.rb | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/commands/routes/routes_command.rb b/railties/lib/rails/commands/routes/routes_command.rb index 41162a4425..b592a5212f 100644 --- a/railties/lib/rails/commands/routes/routes_command.rb +++ b/railties/lib/rails/commands/routes/routes_command.rb @@ -5,19 +5,9 @@ require "rails/command" module Rails 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: "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 + class_option :controller, aliases: "-c", desc: "Filter by a specific controller, e.g. PostsController or Admin::PostsController." + class_option :grep, aliases: "-g", desc: "Grep routes by a specific pattern." + class_option :expanded, type: :boolean, aliases: "-E", desc: "Print routes expanded vertically with parts explained." def perform(*) require_application_and_environment! @@ -32,7 +22,7 @@ module Rails end def formatter - if options.key?("expanded_format") + if options.key?("expanded") ActionDispatch::Routing::ConsoleFormatter::Expanded.new else ActionDispatch::Routing::ConsoleFormatter::Sheet.new @@ -40,7 +30,7 @@ module Rails end def routes_filter - options.symbolize_keys.slice(:controller, :grep_pattern) + options.symbolize_keys.slice(:controller, :grep) end end end -- cgit v1.2.3