Froze rails gems
[depot.git] / vendor / rails / railties / lib / commands / console.rb
1 irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
2
3 require 'optparse'
4
5 options = { :sandbox => false, :irb => irb }
6 OptionParser.new do |opt|
7 opt.banner = "Usage: console [environment] [options]"
8 opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
9 opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
10 opt.on("--debugger", 'Enable ruby-debugging for the console.') { |v| options[:debugger] = v }
11 opt.parse!(ARGV)
12 end
13
14 libs = " -r irb/completion"
15 libs << %( -r "#{RAILS_ROOT}/config/environment")
16 libs << " -r console_app"
17 libs << " -r console_sandbox" if options[:sandbox]
18 libs << " -r console_with_helpers"
19
20 if options[:debugger]
21 begin
22 require 'ruby-debug'
23 libs << " -r ruby-debug"
24 puts "=> Debugger enabled"
25 rescue Exception
26 puts "You need to install ruby-debug to run the console in debugging mode. With gems, use 'gem install ruby-debug'"
27 exit
28 end
29 end
30
31 ENV['RAILS_ENV'] = case ARGV.first
32 when "p"; "production"
33 when "d"; "development"
34 when "t"; "test"
35 else
36 ARGV.first || ENV['RAILS_ENV'] || 'development'
37 end
38
39 if options[:sandbox]
40 puts "Loading #{ENV['RAILS_ENV']} environment in sandbox (Rails #{Rails.version})"
41 puts "Any modifications you make will be rolled back on exit"
42 else
43 puts "Loading #{ENV['RAILS_ENV']} environment (Rails #{Rails.version})"
44 end
45 exec "#{options[:irb]} #{libs} --simple-prompt"