2005-02-17 14:36:49 -05:00
|
|
|
irb = RUBY_PLATFORM =~ /mswin32/ ? 'irb.bat' : 'irb'
|
2005-02-19 16:57:43 -05:00
|
|
|
|
|
|
|
require 'optparse'
|
2005-05-21 06:49:15 -04:00
|
|
|
options = { :sandbox => false, :irb => irb }
|
2005-02-19 16:57:43 -05:00
|
|
|
OptionParser.new do |opt|
|
2005-11-21 00:33:13 -05:00
|
|
|
opt.banner = "Usage: console [environment] [options]"
|
2006-06-28 16:53:00 -04: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 16:57:43 -05:00
|
|
|
opt.parse!(ARGV)
|
|
|
|
end
|
|
|
|
|
2005-04-30 11:37:45 -04:00
|
|
|
libs = " -r irb/completion"
|
2005-09-29 08:33:48 -04:00
|
|
|
libs << " -r #{RAILS_ROOT}/config/environment"
|
2006-03-01 10:52:40 -05:00
|
|
|
libs << " -r console_app"
|
2005-04-30 11:37:45 -04:00
|
|
|
libs << " -r console_sandbox" if options[:sandbox]
|
2006-03-21 15:07:41 -05:00
|
|
|
libs << " -r console_with_helpers"
|
2005-02-19 16:57:43 -05:00
|
|
|
|
2006-11-30 19:08:33 -05: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 16:57:43 -05: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 14:08:04 -05:00
|
|
|
exec "#{options[:irb]} #{libs} --simple-prompt"
|