2005-02-19 21:57:43 +00:00
|
|
|
require 'optparse'
|
2008-09-11 15:06:36 +00:00
|
|
|
|
2009-02-28 23:47:00 +00:00
|
|
|
options = { :sandbox => false }
|
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 }
|
2008-09-11 15:06:36 +00:00
|
|
|
opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v }
|
2005-02-19 21:57:43 +00:00
|
|
|
opt.parse!(ARGV)
|
|
|
|
end
|
|
|
|
|
2009-02-28 23:47:00 +00:00
|
|
|
require 'irb'
|
|
|
|
require "irb/completion"
|
|
|
|
require "#{RAILS_ROOT}/config/environment"
|
|
|
|
require "console_app"
|
|
|
|
require "console_sandbox" if options[:sandbox]
|
|
|
|
require "console_with_helpers"
|
2005-02-19 21:57:43 +00:00
|
|
|
|
2008-09-11 15:06:36 +00:00
|
|
|
if options[:debugger]
|
|
|
|
begin
|
|
|
|
require 'ruby-debug'
|
|
|
|
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-12-01 00:08:33 +00:00
|
|
|
ENV['RAILS_ENV'] = case ARGV.first
|
2007-12-17 18:54:55 +00:00
|
|
|
when "p"; "production"
|
|
|
|
when "d"; "development"
|
|
|
|
when "t"; "test"
|
2006-12-01 00:08:33 +00:00
|
|
|
else
|
|
|
|
ARGV.first || ENV['RAILS_ENV'] || 'development'
|
|
|
|
end
|
|
|
|
|
2005-02-19 21:57:43 +00:00
|
|
|
if options[:sandbox]
|
2008-05-21 23:12:54 +00:00
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails.version})"
|
2007-09-22 22:17:10 +00:00
|
|
|
puts "Any modifications you make will be rolled back on exit"
|
2005-02-19 21:57:43 +00:00
|
|
|
else
|
2008-05-21 23:12:54 +00:00
|
|
|
puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails.version})"
|
2005-02-19 21:57:43 +00:00
|
|
|
end
|
2009-02-28 23:47:00 +00:00
|
|
|
|
|
|
|
ARGV.replace(["--simple-prompt"])
|
|
|
|
IRB.start
|