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

if defined?(RAILS_ENV)
  RAILS_ENV.replace(options[:environment])
else
  ENV["RAILS_ENV"] = options[:environment]
end

require RAILS_ROOT + '/config/environment'
eval(ARGV.first)

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]
RAILS_ENV.replace(options[:environment]) if defined?(RAILS_ENV)

require RAILS_ROOT + '/config/environment'
eval(ARGV.first)

Make sure ENV['RAILS_ENV'] and RAILS_ENV are kept in sync
Make sure ENV['RAILS_ENV'] and RAILS_ENV are kept in sync


git-svn-id: afc9fed30c1a09d8801d1e4fbe6e01c29c67d11f@2539 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
