aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--railties/CHANGELOG2
-rw-r--r--railties/bin/runner24
2 files changed, 26 insertions, 0 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG
index 8f6de2d135..bd621c9032 100644
--- a/railties/CHANGELOG
+++ b/railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added -e/--environment option to script/runner #1408 [fbeausoleil@ftml.net]
+
* Modernize the scaffold generator to use the simplified render and test methods and to change style from @params["id"] to params[:id]. #1367
* Added graceful exit from pressing CTRL-C during the run of the rails command #1150 [Caleb Tennis]
diff --git a/railties/bin/runner b/railties/bin/runner
index acb18f0098..c319bfe658 100644
--- a/railties/bin/runner
+++ b/railties/bin/runner
@@ -1,3 +1,27 @@
+require 'optparse'
+
+options = { :environment => "development" }
+
+ARGV.options do |opts|
+ script_name = File.basename($0)
+ opts.banner = "Usage: runner 'puts Person.find(1).name' [options]"
+
+ opts.separator ""
+
+ opts.on("-e", "--environment=name", String,
+ "Specifies the environment for the runner to operate under (test/development/production).",
+ "Default: development") { |options[:environment]| }
+
+ opts.separator ""
+
+ opts.on("-h", "--help",
+ "Show this help message.") { puts opts; exit }
+
+ opts.parse!
+end
+
+ENV["RAILS_ENV"] = options[:environment]
+
#!/usr/local/bin/ruby
require File.dirname(__FILE__) + '/../config/environment'