Class: ArgParser
Constant Summary
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary
Attributes included from BasicLogging
Class Method Summary collapse
-
.parse(args) ⇒ Object
Returns a structure describing the options.
Methods included from BasicLogging
is_muted?, #log, mute, #set_level, #set_target
Class Method Details
.parse(args) ⇒ Object
Returns a structure describing the options.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/argparser.rb', line 29 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. = OpenStruct.new op = OptionParser.new do |opts| opts.on("-a", "--add", 'Add new event') do .add = 'add' end opts.on("-eEVENT", "--event=EVENT", 'Name of the event') do |ev| .event = ev end opts.on("-yYEAR", "--year=YEAR", 'Year of the event') do |year| .year = year end opts.on("-bINFO", "--background=INFO", 'Background information') do |info| .background = info end opts.on("-fFILE", "--file=FILE", 'The file that events are read from') do |file| .file = file end opts.on("-d", "--debug", 'Be verbose') do .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. puts msg puts "Start this program with parameter -h or --help to see the usage-message." exit false end end |