Class: ArgParser
Class Method Summary collapse
-
.parse(args) ⇒ Object
Returns a structure describing the options.
Methods included from Logging
#init_logger, #log_level=, #log_target=
Class Method Details
.parse(args) ⇒ Object
Returns a structure describing the options.
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 73 74 75 76 77 78 |
# File 'lib/argparser.rb', line 35 def self.parse(args) # The options specified on the command line will be collected in <b>options</b>. # We set default values here. = OpenStruct.new .fast = false .line = 0 .file = nil op = OptionParser.new do |opts| opts. = "Usage:\t" << "%s -s [textfile] <options>" %($0) <<"\n" opts.separator "" opts.separator "Specific options:" opts.on('-' << "sFILE", '--' << "source FILE", "read this file") do |file| .file = file end opts.on('-' << "f", '--' << "fast", "display at once entire lines") do |fast| .fast = true end opts.on('-' << 'lLINE', '--' << "line LINE", "start reading file at line 'line'") do |line| .line = line.to_i - 1 end opts.separator "" opts.separator ("Common options") << ':' # No argument, shows at tail. This will print an options summary. opts.on_tail(("-h"), ("--help"), ("Show this message") ) do puts opts exit true end opts.on_tail(("-v"), ("--version"), ("Show version and program information") ) do puts "\t#{APPNAME}, version #{VERSION} (called as #{$0})" puts "\t© 2015-#{YEAR} #{AUTHOR} #{AMAIL}>" exit true end end op.parse!(args) end |