OptionParser Generator

Build Status Dependency Status Inline docs

Small gem which generates an OptionParser object from an OpenStruct.


gem install optsparser_generator


require 'optsparser_generator'
# step one define OpenStruct with default and special values
os = OpenStruct.new
os.default = 'value'
os.val = 123
os.val__values = [1, 1.5, 2, 123]
os.val__class = Numeric
os.bool = true
os.bool__help = 'description of argument'
os.bool__short = 'b'
os.test = "don't know"
os.test_proc = Proc.new do |value|
    puts value

# step two generate OptionParser
opt_parser = OptParseGen(os)
opt_parser = OptionParserGenerator(os)
# or parse options directly
OptParseGen.parse(os) # takes ARGV or an array

Special values

  • __help defines the description for a property
  • __values defines possible values in an Array
  • __short defines the short trigger
  • __class defines the Class which OptionParser then tries to coerce to
  • __proc a Proc which will be executed to compute the value

Version numbers

I choose two digit version numbers. The first digit indicates breaking changes. Second digit increases per release.