diff --git a/bin/crash-watch b/bin/crash-watch index d6e026c..a42a842 100755 --- a/bin/crash-watch +++ b/bin/crash-watch @@ -1,8 +1,45 @@ #!/usr/bin/env ruby -require 'crash_watch/gdb_controller' +require 'optparse' + +options = {} +parser = OptionParser.new do |opts| + opts.banner = "Usage: crash-watch [options] PID" + opts.separator "" + + opts.separator "Options:" + opts.on("-d", "--debug", "Show GDB commands that crash-watch sends.") do + options[:debug] = true + end + opts.on("-v", "--version", "Show version number.") do + options[:version] = true + end + opts.on("-h", "--help", "Show this help message.") do + options[:help] = true + end +end +begin + parser.parse! +rescue OptionParser::ParseError => e + puts e + puts + puts "Please see '--help' for valid options." + exit 1 +end + +if options[:help] + puts parser + exit +elsif options[:version] + require 'crash_watch/version' + puts "crash-watch version #{CrashWatch::VERSION_STRING}" + exit +end +require 'crash_watch/gdb_controller' gdb = CrashWatch::GdbController.new begin + gdb.debug = options[:debug] + # Ruby sometimes uses SIGVTARLM for thread scheduling. gdb.execute("handle SIGVTALRM noprint pass") diff --git a/crash-watch.gemspec b/crash-watch.gemspec index 011b60a..3e80aeb 100644 --- a/crash-watch.gemspec +++ b/crash-watch.gemspec @@ -1,6 +1,8 @@ +require File.expand_path('lib/crash_watch/version', File.dirname(__FILE__)) + Gem::Specification.new do |s| s.name = "crash-watch" - s.version = "1.0.0" + s.version = CrashWatch::VERSION_STRING s.authors = ["Hongli Lai"] s.date = "2010-04-16" s.description = "Monitor processes and display useful information when they crash." diff --git a/lib/crash_watch/version.rb b/lib/crash_watch/version.rb new file mode 100644 index 0000000..abc69f6 --- /dev/null +++ b/lib/crash_watch/version.rb @@ -0,0 +1,3 @@ +module CrashWatch + VERSION_STRING = '1.0.0' +end \ No newline at end of file