require 'ostruct' require 'optparse' class ArgumentParser def initialize @options = OpenStruct.new @options.scanner = 'scanner' @options.input = STDIN @options.output = nil @options.verbose = false @optionParser = OptionParser.new do |optionParser| optionParser.banner = "Usage: #{optionParser.program_name} [options] [input files]" optionParser.separator '' optionParser.on('-s', '--scanner=BINARY', 'Name of the scanner executable') do |s| @options.scanner = s end optionParser.on('-o', '--output=FILE', 'File where all the output will be written to') do |o| @options.output = o end optionParser.on('-v', '--[no-]verbose', 'Run verbosely') do |v| @options.verbose = v end optionParser.on_tail('-h', '--help', 'Display this') do |h| puts optionParser end end end def parseArguments(args) begin @optionParser.parse!(args) rescue Exception => e puts e, '', @optionParser end @options end end