diff options
Diffstat (limited to 'railties/lib')
-rw-r--r-- | railties/lib/rails/commands/commands_tasks.rb | 28 | ||||
-rw-r--r-- | railties/lib/rails/commands/rake_proxy.rb | 34 |
2 files changed, 28 insertions, 34 deletions
diff --git a/railties/lib/rails/commands/commands_tasks.rb b/railties/lib/rails/commands/commands_tasks.rb index e1713d5798..da3b9452d5 100644 --- a/railties/lib/rails/commands/commands_tasks.rb +++ b/railties/lib/rails/commands/commands_tasks.rb @@ -24,15 +24,18 @@ The most common rails commands are: new Create a new Rails application. "rails new my_app" creates a new application called MyApp in "./my_app" -In addition to those, there are: - destroy Undo code generated with "generate" (short-cut alias: "d") - plugin new Generates skeleton for developing a Rails plugin - runner Run a piece of code in the application environment (short-cut alias: "r") - All commands can be run with -h (or --help) for more information. +In addition to those commands, there are: EOT + ADDITIONAL_COMMANDS = [ + [ 'destroy', 'Undo code generated with "generate" (short-cut alias: "d")' ], + [ 'plugin new', 'Generates skeleton for developing a Rails plugin' ], + [ 'runner', + 'Run a piece of code in the application environment (short-cut alias: "r")' ] + ] + COMMAND_WHITELIST = %w(plugin generate destroy console server dbconsole runner new version help test) def initialize(argv) @@ -45,8 +48,7 @@ EOT if COMMAND_WHITELIST.include?(command) send(command) else - ARGV.unshift(command) - send(:rake) + run_rake_task(command) end end @@ -110,10 +112,6 @@ EOT end end - def rake - invoke_rake - end - def version argv.unshift '--version' require_command!("application") @@ -121,8 +119,7 @@ EOT def help write_help_message - write_rake_tasks_help_message - write_rake_tasks + write_commands ADDITIONAL_COMMANDS + formatted_rake_tasks end private @@ -164,6 +161,11 @@ EOT puts HELP_MESSAGE end + def write_commands(commands) + width = commands.map { |name, _| name.size }.max || 10 + commands.each { |command| printf(" %-#{width}s %s\n", *command) } + end + def parse_command(command) case command when '--version', '-v' diff --git a/railties/lib/rails/commands/rake_proxy.rb b/railties/lib/rails/commands/rake_proxy.rb index 13a9aef694..f7d5df6b2f 100644 --- a/railties/lib/rails/commands/rake_proxy.rb +++ b/railties/lib/rails/commands/rake_proxy.rb @@ -1,42 +1,34 @@ require 'rake' +require 'active_support' module Rails module RakeProxy #:nodoc: - - RAKE_TASKS_HELP_MESSAGE = <<-EOT -In addition to those, you can run the rake tasks as rails commands: - - EOT - private + def run_rake_task(command) + ARGV.unshift(command) # Prepend the command, so Rake knows how to run it. - def write_rake_tasks_help_message - puts RAKE_TASKS_HELP_MESSAGE - end - - def write_rake_tasks - width = rake_tasks.map { |t| t.name_with_args.length }.max || 10 - rake_tasks.each do |t| - printf("#{Rake.application.name} %-#{width}s # %s\n", t.name_with_args, t.comment) + Rake.application.standard_exception_handling do + Rake.application.init('rails') + Rake.application.load_rakefile + Rake.application.top_level end end def rake_tasks return @rake_tasks if defined?(@rake_tasks) - require_application_and_environment! + ActiveSupport::Deprecation.silence do + require_application_and_environment! + end + Rake::TaskManager.record_task_metadata = true Rake.application.instance_variable_set(:@name, 'rails') Rails.application.load_tasks @rake_tasks = Rake.application.tasks.select(&:comment) end - def invoke_rake - Rake.application.standard_exception_handling do - Rake.application.init('rails') - Rake.application.load_rakefile - Rake.application.top_level - end + def formatted_rake_tasks + rake_tasks.map { |t| [ t.name_with_args, t.comment ] } end end end |