aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/rails-2.0.2/railties/lib/commands/runner.rb
diff options
context:
space:
mode:
authorfrancis <francis>2008-01-23 01:48:14 +0000
committerfrancis <francis>2008-01-23 01:48:14 +0000
commit60eaae4f7df1f1dae91defb87d3707451c359cf4 (patch)
treee74835c37779a2f094e810960cda07b99a75330e /vendor/rails-2.0.2/railties/lib/commands/runner.rb
parent71d22c740302e1f83bbbd89b229734ea9c67493c (diff)
Freeze in rails 2.0.2 (Am I going to regret having this beast in CVS?)
Diffstat (limited to 'vendor/rails-2.0.2/railties/lib/commands/runner.rb')
-rw-r--r--vendor/rails-2.0.2/railties/lib/commands/runner.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/vendor/rails-2.0.2/railties/lib/commands/runner.rb b/vendor/rails-2.0.2/railties/lib/commands/runner.rb
new file mode 100644
index 000000000..926bc2634
--- /dev/null
+++ b/vendor/rails-2.0.2/railties/lib/commands/runner.rb
@@ -0,0 +1,48 @@
+require 'optparse'
+
+options = { :environment => (ENV['RAILS_ENV'] || "development").dup }
+code_or_file = nil
+
+ARGV.clone.options do |opts|
+ script_name = File.basename($0)
+ opts.banner = "Usage: #{$0} [options] ('Some.ruby(code)' or a filename)"
+
+ opts.separator ""
+
+ opts.on("-e", "--environment=name", String,
+ "Specifies the environment for the runner to operate under (test/development/production).",
+ "Default: development") { |v| options[:environment] = v }
+
+ opts.separator ""
+
+ opts.on("-h", "--help",
+ "Show this help message.") { $stderr.puts opts; exit }
+
+ if RUBY_PLATFORM !~ /mswin/
+ opts.separator ""
+ opts.separator "You can also use runner as a shebang line for your scripts like this:"
+ opts.separator "-------------------------------------------------------------"
+ opts.separator "#!/usr/bin/env #{File.expand_path($0)}"
+ opts.separator ""
+ opts.separator "Product.find(:all).each { |p| p.price *= 2 ; p.save! }"
+ opts.separator "-------------------------------------------------------------"
+ end
+
+ opts.order! { |o| code_or_file ||= o } rescue retry
+end
+
+ARGV.delete(code_or_file)
+
+ENV["RAILS_ENV"] = options[:environment]
+RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)
+
+require RAILS_ROOT + '/config/environment'
+
+if code_or_file.nil?
+ $stderr.puts "Run '#{$0} -h' for help."
+ exit 1
+elsif File.exist?(code_or_file)
+ eval(File.read(code_or_file))
+else
+ eval(code_or_file)
+end