diff options
author | Vipul A M <vipulnsward@gmail.com> | 2016-01-25 01:32:44 +0530 |
---|---|---|
committer | Vipul A M <vipulnsward@gmail.com> | 2016-02-02 00:27:30 +0530 |
commit | 8a436fdd98c63cc0a7a6d2c642c18d33421dc6ad (patch) | |
tree | 07bd88344185093d8a692cbd6606afa4eb50d372 /railties/lib/rails | |
parent | 25a42755403ba4a8d9a4128d5ff6483ca2fd9252 (diff) | |
download | rails-8a436fdd98c63cc0a7a6d2c642c18d33421dc6ad.tar.gz rails-8a436fdd98c63cc0a7a6d2c642c18d33421dc6ad.tar.bz2 rails-8a436fdd98c63cc0a7a6d2c642c18d33421dc6ad.zip |
Add options for rake routes task
Add two options: `-c` and `-g`.
`-g` option returns the urls name, verb and path fields that match the pattern.
`-c` option returns the urls for specific controller.
Fixes #18902, and Fixes #20420
[Anton Davydov & Vipul A M]
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/tasks/routes.rake | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/railties/lib/rails/tasks/routes.rake b/railties/lib/rails/tasks/routes.rake index 1815c2fdc7..499c434ffa 100644 --- a/railties/lib/rails/tasks/routes.rake +++ b/railties/lib/rails/tasks/routes.rake @@ -1,7 +1,35 @@ -desc 'Print out all defined routes in match order, with names. Target specific controller with CONTROLLER=x.' +require 'active_support/deprecation' +require 'active_support/core_ext/string/strip' # for strip_heredoc +require 'optparse' + +desc 'Print out all defined routes in match order, with names. Target specific controller with --controller option - or its -c shorthand.' task routes: :environment do all_routes = Rails.application.routes.routes require 'action_dispatch/routing/inspector' inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes) - puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER']) + if ARGV.any?{ |argv| argv.start_with? 'CONTROLLER' } + puts <<-eow.strip_heredoc + Passing `CONTROLLER` to `bin/rake routes` is deprecated and will be removed in Rails 5.1. + Please use `bin/rake routes -c controller_name` instead. + eow + end + + routes_filter = nil + routes_filter = {controller: ENV['CONTROLLER']} if ENV['CONTROLLER'] + + OptionParser.new do |opts| + opts.banner = "Usage: rake routes [options]" + opts.on("-c", "--controller [CONTROLLER]") do |controller| + routes_filter = { controller: controller } + end + + opts.on("-g", "--grep [PATTERN]") do |pattern| + routes_filter = pattern + end + + end.parse!(ARGV.reject { |x| x == "routes" }) + + puts inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, routes_filter) + + exit 0 # ensure extra arguments aren't interpreted as Rake tasks end |