Skip to content

Commit c98cb8f

Browse files
miloopsNZKoz
authored andcommitted
Add --debugger option to script/console.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1025 state:committed]
1 parent 1ddde91 commit c98cb8f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

railties/lib/commands/console.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
22

33
require 'optparse'
4+
45
options = { :sandbox => false, :irb => irb }
56
OptionParser.new do |opt|
67
opt.banner = "Usage: console [environment] [options]"
78
opt.on('-s', '--sandbox', 'Rollback database modifications on exit.') { |v| options[:sandbox] = v }
89
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 }
911
opt.parse!(ARGV)
1012
end
1113

@@ -15,6 +17,17 @@
1517
libs << " -r console_sandbox" if options[:sandbox]
1618
libs << " -r console_with_helpers"
1719

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+
1831
ENV['RAILS_ENV'] = case ARGV.first
1932
when "p"; "production"
2033
when "d"; "development"

0 commit comments

Comments
 (0)