aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
Diffstat (limited to 'railties')
-rw-r--r--railties/CHANGELOG6
-rwxr-xr-xrailties/bin/rails47
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/about3
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/console.tt5
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/dbconsole.tt5
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/destroy2
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/generate2
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/performance/benchmarker2
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/performance/profiler2
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/plugin2
-rw-r--r--railties/lib/generators/rails/app/templates/script/rails6
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/runner3
-rwxr-xr-xrailties/lib/generators/rails/app/templates/script/server.tt5
-rw-r--r--railties/lib/rails/commands/application.rb12
-rw-r--r--railties/lib/rails/commands/rails.rb69
15 files changed, 118 insertions, 53 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index fc9277bd28..4176d7fcad 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,11 @@
*Edge*
+* Removed all the default commands in script/* and replaced them with script/rails and a rails command that'll act the same when run from within the app [DHH]. Example:
+
+ ./script/generate scaffold post title:string can now be called as rails g scaffold post title:string
+
+ Run rails --help inside an app for more help.
+
* Removed config/initializers/new_rails_defaults.rb as all frameworks now follow the settings from it [DHH]
* Set config.time_zone to UTC by default [DHH]
diff --git a/railties/bin/rails b/railties/bin/rails
index afcd9fd0be..44842e2234 100755
--- a/railties/bin/rails
+++ b/railties/bin/rails
@@ -1,27 +1,30 @@
-begin
- require 'rails/ruby_version_check'
-rescue LoadError
- # If people are not using gems, the load path must still
- # be correct.
- # TODO: Remove the begin / rescue block somehow
- $:.unshift File.expand_path('../../lib', __FILE__)
- $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
- $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
- require 'rails/ruby_version_check'
-end
+if File.exists?(Dir.getwd + '/script/rails')
+ exec(Dir.getwd + '/script/rails', *ARGV)
+else
+ begin
+ require 'rails/ruby_version_check'
+ rescue LoadError
+ # If people are not using gems, the load path must still
+ # be correct.
+ # TODO: Remove the begin / rescue block somehow
+ $:.unshift File.expand_path('../../lib', __FILE__)
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
+ $:.unshift File.expand_path('../../../actionpack/lib', __FILE__)
+ require 'rails/ruby_version_check'
+ end
-Signal.trap("INT") { puts; exit }
+ Signal.trap("INT") { puts; exit }
-require 'rails/version'
-if %w(--version -v).include? ARGV.first
- puts "Rails #{Rails::VERSION::STRING}"
- exit(0)
-end
+ require 'rails/version'
+ if %w(--version -v).include? ARGV.first
+ puts "Rails #{Rails::VERSION::STRING}"
+ exit(0)
+ end
-ARGV << "--help" if ARGV.empty?
+ ARGV << "--help" if ARGV.empty?
+ require 'rails/generators'
+ require 'generators/rails/app/app_generator'
-require 'rails/generators'
-require 'generators/rails/app/app_generator'
-
-Rails::Generators::AppGenerator.start
+ Rails::Generators::AppGenerator.start
+end \ No newline at end of file
diff --git a/railties/lib/generators/rails/app/templates/script/about b/railties/lib/generators/rails/app/templates/script/about
deleted file mode 100755
index 93fd007649..0000000000
--- a/railties/lib/generators/rails/app/templates/script/about
+++ /dev/null
@@ -1,3 +0,0 @@
-require File.expand_path('../../config/environment', __FILE__)
-$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
-require 'rails/commands/about'
diff --git a/railties/lib/generators/rails/app/templates/script/console.tt b/railties/lib/generators/rails/app/templates/script/console.tt
deleted file mode 100755
index 47aa254f9f..0000000000
--- a/railties/lib/generators/rails/app/templates/script/console.tt
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/console'
-require File.expand_path('../../config/application', __FILE__)
-
-Rails::Console.start(Rails::Application)
diff --git a/railties/lib/generators/rails/app/templates/script/dbconsole.tt b/railties/lib/generators/rails/app/templates/script/dbconsole.tt
deleted file mode 100755
index 1e53c1d761..0000000000
--- a/railties/lib/generators/rails/app/templates/script/dbconsole.tt
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/dbconsole'
-require File.expand_path('../../config/application', __FILE__)
-
-Rails::DBConsole.start(Rails::Application)
diff --git a/railties/lib/generators/rails/app/templates/script/destroy b/railties/lib/generators/rails/app/templates/script/destroy
deleted file mode 100755
index adfa8e8426..0000000000
--- a/railties/lib/generators/rails/app/templates/script/destroy
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/commands/destroy'
diff --git a/railties/lib/generators/rails/app/templates/script/generate b/railties/lib/generators/rails/app/templates/script/generate
deleted file mode 100755
index 6fb8ad0395..0000000000
--- a/railties/lib/generators/rails/app/templates/script/generate
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path('../../config/environment', __FILE__)
-require 'rails/commands/generate'
diff --git a/railties/lib/generators/rails/app/templates/script/performance/benchmarker b/railties/lib/generators/rails/app/templates/script/performance/benchmarker
deleted file mode 100755
index 9647d8f10a..0000000000
--- a/railties/lib/generators/rails/app/templates/script/performance/benchmarker
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path('../../../config/environment', __FILE__)
-require 'rails/commands/performance/benchmarker'
diff --git a/railties/lib/generators/rails/app/templates/script/performance/profiler b/railties/lib/generators/rails/app/templates/script/performance/profiler
deleted file mode 100755
index a5822042d2..0000000000
--- a/railties/lib/generators/rails/app/templates/script/performance/profiler
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path('../../../config/environment', __FILE__)
-require 'rails/commands/performance/profiler'
diff --git a/railties/lib/generators/rails/app/templates/script/plugin b/railties/lib/generators/rails/app/templates/script/plugin
deleted file mode 100755
index 1f1af6c880..0000000000
--- a/railties/lib/generators/rails/app/templates/script/plugin
+++ /dev/null
@@ -1,2 +0,0 @@
-require File.expand_path('../../config/application', __FILE__)
-require 'rails/commands/plugin'
diff --git a/railties/lib/generators/rails/app/templates/script/rails b/railties/lib/generators/rails/app/templates/script/rails
new file mode 100644
index 0000000000..038547598e
--- /dev/null
+++ b/railties/lib/generators/rails/app/templates/script/rails
@@ -0,0 +1,6 @@
+ENV_PATH = File.expand_path('../../config/environment', __FILE__)
+BOOT_PATH = File.expand_path('../../config/boot', __FILE__)
+APP_PATH = File.expand_path('../../config/application', __FILE__)
+
+require BOOT_PATH
+require 'rails/commands/rails'
diff --git a/railties/lib/generators/rails/app/templates/script/runner b/railties/lib/generators/rails/app/templates/script/runner
deleted file mode 100755
index 3354ed4a28..0000000000
--- a/railties/lib/generators/rails/app/templates/script/runner
+++ /dev/null
@@ -1,3 +0,0 @@
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/runner'
-require File.expand_path('../../config/environment', __FILE__)
diff --git a/railties/lib/generators/rails/app/templates/script/server.tt b/railties/lib/generators/rails/app/templates/script/server.tt
deleted file mode 100755
index 4fd0cc7832..0000000000
--- a/railties/lib/generators/rails/app/templates/script/server.tt
+++ /dev/null
@@ -1,5 +0,0 @@
-require File.expand_path('../../config/boot', __FILE__)
-require 'rails/commands/server'
-
-Dir.chdir(File.expand_path('../..', __FILE__))
-Rails::Server.start
diff --git a/railties/lib/rails/commands/application.rb b/railties/lib/rails/commands/application.rb
new file mode 100644
index 0000000000..0f09e7eafb
--- /dev/null
+++ b/railties/lib/rails/commands/application.rb
@@ -0,0 +1,12 @@
+require 'rails/version'
+if %w(--version -v).include? ARGV.first
+ puts "Rails #{Rails::VERSION::STRING}"
+ exit(0)
+end
+
+ARGV << "--help" if ARGV.empty?
+
+require 'rails/generators'
+require 'generators/rails/app/app_generator'
+
+Rails::Generators::AppGenerator.start \ No newline at end of file
diff --git a/railties/lib/rails/commands/rails.rb b/railties/lib/rails/commands/rails.rb
new file mode 100644
index 0000000000..a2f86028ec
--- /dev/null
+++ b/railties/lib/rails/commands/rails.rb
@@ -0,0 +1,69 @@
+if ARGV.empty?
+ ARGV << '--help'
+end
+
+HELP_TEXT = <<-EOT
+usage: rails COMMAND [ARGS]
+
+The most common rails commands are:
+ generate Generate new code (short-cut alias: "g")
+ console Start the Rails console (short-cut alias: "c")
+ server Start the Rails server (short-cut alias: "s")
+
+In addition to those, there are:
+ application Generate the Rails application code
+ dbconsole Start a console for the database specified in config/database.yml
+ destroy Undo code generated with "generate"
+ benchmarker See how fast a piece of code runs
+ profiler Get profile information from a piece of code
+ plugin Install a plugin
+ 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 BOOT_PATH
+ require 'rails/commands/console'
+ require APP_PATH
+ Rails::Console.start(Rails::Application)
+when 's', 'server'
+ require File.expand_path('../../config/boot', __FILE__)
+ require 'rails/commands/server'
+ Dir.chdir(File.expand_path('../..', __FILE__))
+ Rails::Server.start
+
+
+when 'dbconsole'
+ require BOOT_PATH
+ require 'rails/commands/dbconsole'
+ require APP_PATH
+ Rails::DBConsole.start(Rails::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 BOOT_PATH
+ require 'rails/commands/runner'
+ require ENV_PATH
+
+when '--help', '-h'
+ puts HELP_TEXT
+else
+ puts "Error: Command not recognized"
+ puts HELP_TEXT
+end \ No newline at end of file