aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails/commands.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2010-05-01 02:23:47 -0700
committerXavier Noria <fxn@hashref.com>2010-05-01 02:23:47 -0700
commitefba1d4227514a6ce4880910a6531b0a6c3c75aa (patch)
treedaff4155b8c19b915125ac0b0da458279358e743 /railties/lib/rails/commands.rb
parent81807e0fe2879e08563c91ee6809ab6d1d0bd081 (diff)
parent6c280f3398966ffba45069500ff43d632513fe44 (diff)
downloadrails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.tar.gz
rails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.tar.bz2
rails-efba1d4227514a6ce4880910a6531b0a6c3c75aa.zip
Merge commit 'rails/master'
Conflicts: railties/guides/source/index.html.erb
Diffstat (limited to 'railties/lib/rails/commands.rb')
-rw-r--r--railties/lib/rails/commands.rb102
1 files changed, 48 insertions, 54 deletions
diff --git a/railties/lib/rails/commands.rb b/railties/lib/rails/commands.rb
index 12748da18b..de93a87615 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', 'profiler'
+ 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