The project is in a healthy, maintained state
No-code options parser that extracts arguments directly from usage text.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Options by Example

No-code options parser that automatically detects command-line options from the usage text.

Features

  • Automatically infers options and argument names from usage text
  • Parses those arguments and options from the command line (ARGV)
  • Raises errors for unknown options or missing required arguments

Example

require %(options_by_example)

flags = OptionsByExample.read(DATA).parse(ARGV)

puts 'Feeling verbose today' if flags.include?(:verbose)
puts flags.get(:words).sample(flags.get(:num))

__END__
Choose at random from a list of provided words.

Usage: random.rb [options] words ...

Options:
  -n, --num NUM     Number of choices (default 1)
  --verbose         Enable verbose mode

And then call the program with eg

ruby random.rb -n 2 foo bar qux

Installation

To use options_by_example, first install the gem by running:

gem install options_by_example

Alternatively, add this line to your Gemfile and run bundle install:

gem 'options_by_example'