Class: Nicolus::OptParse
Overview
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
# File 'lib/opt_parse.rb', line 14 def self.parse(args) = {} opts = OptionParser.new do |opts| opts. = "Usage: \n\tnicolus --input listes.csv --output combinaison.csv\n\tnicolus -i listes.csv -o combinaison.csv --inverse\n" opts.separator "" opts.separator "Mandatory options:" opts.on("-i", "--input [FILE]", :REQUIRED, String, "Csv File with lists of words") do |i| [:input] = i end opts.on("-o", "--output [FILE]", :REQUIRED, String, "Csv File to store the result") do |o| [:output] = o end opts.separator "" opts.separator "Optional options:" opts.on("-I", "--inverse", "Generate inverse combinaison") do |inv| [:inverse] = inv end opts.on("-U", "--unicode", "Input is Unicode") do |unicode| [:unicode] = unicode 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 end end if (args.size == 0) # No args specify > running help opts.parse!(["--help"]) else opts.parse!(args) end end |