aboutsummaryrefslogblamecommitdiffstats
path: root/railties/lib/commands/runner.rb
blob: 47186d52e454e773919e4f196540f9cd44dc6ed0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                  
                                                                     








                                                                                                     
                                                                   








                                                        

                                                               
 
                                          
                                                                       
require 'optparse'

options = { :environment => (ENV['RAILS_ENV'] || "development").dup }

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") { |v| options[:environment] = v }

  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'
ARGV.empty? ? puts("Usage: runner 'code' [options]") : eval(ARGV.first)