Low commit activity in last 3 years
A long-lived project that still receives updates
Generates OptionParser using an OpenStruct
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

< 4, >= 3.5.0
< 1, >= 0.12.0
< 1, >= 0.8
< 14, >= 11.2.0

Runtime

 Project Readme

OptionParser Generator

Inline docs Github actions tests badge

Small gem which generates an OptionParser object from an OpenStruct.

Installation

gem install optsparser_generator

Usage

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.val__required = true
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
	"some-#{value}-conversion"
end
os.freeze

# step two generate OptionParser
opt_parser = OptParseGen(os)
opt_parser = OptionParserGenerator(os)
opt_parser.parse!(ARGV)
# 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
  • __required parameter is required, raises error if missing

Version numbers

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

Enjoy