aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/commands/runner.rb
blob: c7a70a1b0baa6d957418ee99279eda33728f062f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)