2007-03-06 09:22:07 +00:00
|
|
|
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
2005-02-19 21:57:43 +00:00
|
|
|
|
|
|
|
require 'optparse'
|
2005-05-21 10:49:15 +00:00
|
|
|
options = { :sandbox => false, :irb => irb }
|
2005-02-19 21:57:43 +00:00
|
|
|
OptionParser.new do |opt|
|
2005-11-21 05:33:13 +00:00
|
|
|
opt.banner = "Usage: console [environment] [options]"
|
2006-06-28 20:53:00 +00:00
|
|
|
opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
|
|
|
|
opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
|
2005-02-19 21:57:43 +00:00
|
|
|
opt.parse!(ARGV)
|
|
|
|
end
|
|
|
|
|
2005-04-30 15:37:45 +00:00
|
|
|
libs = " -r irb/completion"
|
2005-09-29 12:33:48 +00:00
|
|
|
libs << " -r #{RAILS_ROOT}/config/environment"
|
2006-03-01 15:52:40 +00:00
|
|
|
libs << " -r console_app"
|
2005-04-30 15:37:45 +00:00
|
|
|
libs << " -r console_sandbox" if options[:sandbox]
|
2006-03-21 20:07:41 +00:00
|
|
|
libs << " -r console_with_helpers"
|
2005-02-19 21:57:43 +00:00
|
|
|
|
2006-12-01 00:08:33 +00:00
|
|
|
ENV['RAILS_ENV'] = case ARGV.first
|
|
|
|
when "p": "production"
|
|
|
|
when "d": "development"
|
|
|
|
when "t": "test"
|
|
|
|
else
|
|
|
|
ARGV.first || ENV['RAILS_ENV'] || 'development'
|
|
|
|
end
|
|
|
|
|
2005-02-19 21:57:43 +00:00
|
|
|
if options[:sandbox]
|
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment in sandbox."
|
|
|
|
puts "Any modifications you make will be rolled back on exit."
|
|
|
|
else
|
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment."
|
|
|
|
end
|
2006-04-01 19:08:04 +00:00
|
|
|
exec "#{options[:irb]} #{libs} --simple-prompt"
|