0.0
No release in over 3 years
Low commit activity in last 3 years
Simple options parser inspired by slop
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

= 5.4.2
~> 12.3
 Project Readme

Options

A tiny option parser inspired by slop.

Original idea is taken from Slop option parser (https://github.com/leejarvis/slop).

I make a simpler syntax for my needs. Many thanks to Lee Jarvis.

Usage

Options parses somes words:

  • banner : banner add text to the help message. Help message is displayed with implicit option -h|--help|?|help.
  • flag : Linux style boolean option. For example [--verbose] sets verbose flag true. Short option is the first letter of the long option name.
  • value : Linux style option. Next argument is the value of the option. For example [--name pyer] means name='pyer'. Short option is the first letter of the long option name, as flag option.
  • command : Git style sub-commands, For example [programm status --verbose] means programm executes status command in verbose mode.
  • cmd : alias of command
opts = Options.parse do
  banner 'Some help text'
  value  'name',     'Your name'
  value  'password', 'Your password'
  flag   'verbose',   'Enable verbose mode'
end

# if ARGV is `--name Lee -v`
opts.verbose?  #=> true
opts.password? #=> false
opts.other?    #=> false
opts.name?     #=> true
opts[:name]    #=> 'Lee'
opts.to_hash   #=> {:name=>"Lee", :password=>nil, :verbose=>true}

Installation

gem install pyer-options

Build

Building pyer-options gem is a rake task.

rake build

Test

rake test

Help

Options attempts to build a good looking help string to print to your users. You can get this string by calling opts.help method. The options '-h', '--help' and '?' are available and show this help.

Example:

# example.rb
require 'pyer/options'
opts = Options.parse do
  banner 'Hello world'
  flag   :foo, 'Enable foo mode'
end

ruby example.rb --help ("ruby example.rb -h" or "ruby example.rb ?" give the same result)

Usage: example.rb [options]
  Hello world
Options:
    -f|--foo       : Enable foo mode