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