Class: ArgParser
Class Method Summary collapse
-
.parse(args) ⇒ Object
Returns a structure describing the options.
-
.usage ⇒ Object
Shows the usage-message.
Methods included from BasicLogging
clear_log, is_muted?, level, log, mute, set_level, set_target, target
Class Method Details
.parse(args) ⇒ Object
Returns a structure describing the options.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/argparser.rb', line 31 def self.parse(args) if args.empty? puts usage exit true end # 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 .target = nil op = OptionParser.new do |opts| opts. = usage opts.on("-d", "--debug", 'Be verbose') do $log_level = BasicLogging::DEBUG set_level BasicLogging::DEBUG end opts.on("-sOURCE", "--source=SOURCE", 'Source document (html)') do |so| .source = so end opts.on("-oUT", "--out=GLOSSAR", 'Glossar-file (html)') do |ta| .target = ta end opts.on("-tEMPLATE", "--template=TEMPLATE", 'Template (html)') do |tpl| .template = tpl end opts.on("-cONFIG", "--config=CONFIG", 'Configuration-file') do |cfg| .config = cfg end opts.on("-h", "--help", 'Show this message') do puts opts exit true 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 |
.usage ⇒ Object
Shows the usage-message
93 94 95 96 97 |
# File 'lib/argparser.rb', line 93 def self::usage msg = "\n\tUsage: html2index -s input.html \n\t\t[-o output.html] \n\t\t[-c config-file] \n\t\t[-t template.html] \n\t\t[-d]" msg << "\n\n\t* Will print to stdout, if the output-file is not provided." msg << "\n\t* Adapt ~/.config/HTML2Index/config to your needs.\n\n" end |