2009-03-01 22:03:38 -05:00
|
|
|
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
|
|
|
|
2005-02-19 16:57:43 -05:00
|
|
|
require 'optparse'
|
2008-09-11 11:06:36 -04:00
|
|
|
|
2009-03-01 22:03:38 -05: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 }
|
2009-03-01 22:03:38 -05:00
|
|
|
opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
|
2008-09-11 11:06:36 -04:00
|
|
|
opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v }
|
2005-02-19 16:57:43 -05:00
|
|
|
opt.parse!(ARGV)
|
|
|
|
end
|
|
|
|
|
2009-03-01 22:03:38 -05:00
|
|
|
libs = " -r irb/completion"
|
|
|
|
libs << %( -r "#{RAILS_ROOT}/config/environment")
|
|
|
|
libs << " -r console_app"
|
|
|
|
libs << " -r console_sandbox" if options[:sandbox]
|
|
|
|
libs << " -r console_with_helpers"
|
2005-02-19 16:57:43 -05:00
|
|
|
|
2008-09-11 11:06:36 -04:00
|
|
|
if options[:debugger]
|
|
|
|
begin
|
|
|
|
require 'ruby-debug'
|
2009-03-01 22:03:38 -05:00
|
|
|
libs << " -r ruby-debug"
|
2008-09-11 11:06:36 -04:00
|
|
|
puts "=> Debugger enabled"
|
|
|
|
rescue Exception
|
|
|
|
puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2006-11-30 19:08:33 -05:00
|
|
|
ENV['RAILS_ENV'] = case ARGV.first
|
2007-12-17 13:54:55 -05:00
|
|
|
when "p"; "production"
|
|
|
|
when "d"; "development"
|
|
|
|
when "t"; "test"
|
2006-11-30 19:08:33 -05:00
|
|
|
else
|
|
|
|
ARGV.first || ENV['RAILS_ENV'] || 'development'
|
|
|
|
end
|
|
|
|
|
2005-02-19 16:57:43 -05:00
|
|
|
if options[:sandbox]
|
2008-05-21 19:12:54 -04:00
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails.version})"
|
2007-09-22 18:17:10 -04:00
|
|
|
puts "Any modifications you make will be rolled back on exit"
|
2005-02-19 16:57:43 -05:00
|
|
|
else
|
2008-05-21 19:12:54 -04:00
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails.version})"
|
2005-02-19 16:57:43 -05:00
|
|
|
end
|
2009-03-01 22:03:38 -05:00
|
|
|
exec "#{options[:irb]} #{libs} --simple-prompt"
|