class ArgParser
Public Class Methods
parse(args)
click to toggle source
Returns a structure describing the options.
# File lib/argparser.rb, line 39 def self.parse(args) # The options specified on the command line will be collected in # <b>options</b>. No defaults. Most options are optional and do not # have to be set at all. # The others must be named for each transformation or be set in the # configuration-file. options = OpenStruct.new op = OptionParser.new do |opts| opts.on("-a", "--add", 'Add new event') do options.add = 'add' end opts.on("-eEVENT", "--event=EVENT", 'Name of the event') do |ev| options.event = ev end opts.on("-yYEAR", "--year=YEAR", 'Year of the event') do |year| options.year = year end opts.on("-bINFO", "--background=INFO", 'Background information') do |info| options.background = info end opts.on("-fFILE", "--file=FILE", 'The file, where events are read from') do |file| options.file = file end opts.on("-d", "--debug", 'Be verbose') do options.debug = 'debug' end opts.on("-v", "--version", 'Show program version') do puts $APPNAME.dup << ", version " << $VERSION exit true end end begin op.parse!(args) rescue OptionParser::ParseError => er msg = "ERROR! Unsuitable or incomplete program-arguments" << ": %s" %er.message puts msg puts "Start this program with parameter -h or --help to see the usage-message." exit false end options end