5 require 'webrick/htmlutils'
7 BACKTRACE_SEPARATOR = "\n\tfrom "
9 options = { :html_exceptions => false }
10 OptionParser.new do |opts|
11 opts.banner = "Usage: #{File.basename($0)} [options] [patch-file]"
15 opts.on("--html-exceptions", "Print exceptions to stdout as HTML") { |h| options[:html_exceptions] = h }
19 if ARGV.length == 0 || ARGV[0] == '-' then
20 patch_data = $stdin.read
22 File.open(ARGV[0]) { |file| patch_data = file.read }
26 puts PrettyPatch.prettify(patch_data)
28 raise unless options[:html_exceptions]
30 backtrace = exception.backtrace
31 backtrace[0] += ": " + exception + " (" + exception.class.to_s + ")"
32 print "<pre>\n", WEBrick::HTMLUtils::escape(backtrace.join(BACKTRACE_SEPARATOR)), "\n</pre>\n"