From 1b816d502444ce2b3153d8c689d0057f1c257eee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 29 Apr 2010 08:39:44 +0200 Subject: The rake task :environment now loads config/environment.rb instead of initializing the application on its own. This fixes [#4492 state:resolved] and also avoids the application being initialized twice in some rake tasks. --- railties/lib/rails/commands.rb | 102 +++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 54 deletions(-) (limited to 'railties/lib/rails/commands.rb') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index 12748da18b..c8254f588f 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -1,8 +1,50 @@ -if ARGV.empty? - ARGV << '--help' -end +ARGV << '--help' if ARGV.empty? -HELP_TEXT = <<-EOT +aliases = { + "g" => "generate", + "c" => "console", + "s" => "server", + "db" => "dbconsole" +} + +command = ARGV.shift +command = aliases[command] || command + +case command +when 'generate', 'destroy', 'plugin', 'benchmarker', 'performance' + require APP_PATH + Rails::Application.require_environment! + require "rails/commands/#{command}" + +when 'console' + require 'rails/commands/console' + require APP_PATH + Rails::Application.require_environment! + Rails::Console.start(Rails::Application) + +when 'server' + require 'rails/commands/server' + Rails::Server.new.tap { |server| + require APP_PATH + Dir.chdir(Rails::Application.root) + server.start + } + +when 'dbconsole' + require 'rails/commands/dbconsole' + require APP_PATH + Rails::DBConsole.start(Rails::Application) + +when 'application', 'runner' + require "rails/commands/#{command}" + +when '--version', '-v' + ARGV.unshift '--version' + require 'rails/commands/application' + +else + puts "Error: Command not recognized" unless %w(-h --help).include?(command) + puts <<-EOT Usage: rails COMMAND [ARGS] The most common rails commands are: @@ -21,53 +63,5 @@ In addition to those, there are: runner Run a piece of code in the application environment All commands can be run with -h for more information. -EOT - - -case ARGV.shift -when 'g', 'generate' - require ENV_PATH - require 'rails/commands/generate' -when 'c', 'console' - require 'rails/commands/console' - require ENV_PATH - Rails::Console.start(Rails::Application) -when 's', 'server' - require 'rails/commands/server' - # Initialize the server first, so environment options are set - server = Rails::Server.new - require APP_PATH - - Dir.chdir(Rails::Application.root) - server.start -when 'db', 'dbconsole' - require 'rails/commands/dbconsole' - require APP_PATH - Rails::DBConsole.start(Rails::Application) - -when 'application' - require 'rails/commands/application' -when 'destroy' - require ENV_PATH - require 'rails/commands/destroy' -when 'benchmarker' - require ENV_PATH - require 'rails/commands/performance/benchmarker' -when 'profiler' - require ENV_PATH - require 'rails/commands/performance/profiler' -when 'plugin' - require APP_PATH - require 'rails/commands/plugin' -when 'runner' - require 'rails/commands/runner' - -when '--help', '-h' - puts HELP_TEXT -when '--version', '-v' - ARGV.unshift '--version' - require 'rails/commands/application' -else - puts "Error: Command not recognized" - puts HELP_TEXT -end + EOT +end \ No newline at end of file -- cgit v1.2.3 From 1bea5c755c25cd90171477fe725e64b26395b810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 29 Apr 2010 09:31:06 +0200 Subject: Ops. Rename performance to profiler. --- railties/lib/rails/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/lib/rails/commands.rb') diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb index c8254f588f..de93a87615 100644 --- a/railties/lib/rails/commands.rb +++ b/railties/lib/rails/commands.rb @@ -11,7 +11,7 @@ command = ARGV.shift command = aliases[command] || command case command -when 'generate', 'destroy', 'plugin', 'benchmarker', 'performance' +when 'generate', 'destroy', 'plugin', 'benchmarker', 'profiler' require APP_PATH Rails::Application.require_environment! require "rails/commands/#{command}" -- cgit v1.2.3