Project

miniparse

0.0
No commit activity in last 3 years
No release in over 3 years
miniparse is an easy to use yet flexible and powerful Ruby library for parsing command-line options.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.11
~> 5.0
~> 10.0
~> 3.0
 Project Readme

miniparse Gem version

Miniparse is an easy to use yet flexible and powerful Ruby library for parsing command-line options.

The main objective of this implementation is to get minimun boiler plate but keep ease of use and a self documenting specification.

Additionally the library is quite flexible and allows a lot of customization but always with sane defaults so you don't need to learn nothing to start using it.

How to Use

Please find below a short but meaningful example, then you can get more examples at Github Miniparse repository.

You can also find a nice documentation from the current version at the Miniparse web site

I used to link to the documentation generated by the rubydoc.info site but no more!. It is way worse than looking straight into the source files given it doesn't use and strips out the yard comments on the source files.

And finally, the source files for the complete public interface are:

Simple Example

Let's try putting the following code in myprogram.rb

require 'miniparse'

parser = Miniparse::Parser.new
parser.add_option "--debug", "activate debugging"
parser.parse ARGV

if parser.options[:debug]
  puts "DEBUG ACTIVATED!"
else
  puts "run silently"
end

Now you can run

$ ruby myprogram.rb

run silently

or run

$ ruby myprogram.rb --debug

DEBUG ACTIVATED!

or even get the auto generated help

$ ruby yourprogram.rb --help

usage: ex01_simple.rb [--help] [--debug] <args>

Options:
   --debug          activate debugging

Installation

You can install it as an standard Ruby gem with

$ gem install miniparse

then to use you can require it adding the following to the top of your Ruby source file

require 'miniparse'

FAQ

There is a FAQ available.

Contributing

Bug reports and pull requests are most welcome at https://github.com/jmrod4/miniparse.

After checking out the repo you can:

  • run bin/setup to install dependencies
  • then run rake test to run the tests
  • you can also run bin/console for an interactive prompt that will allow you to experiment
  • run bundle exec miniparse to use the gem in this directory, ignoring other installed copies of this gem
  • run rake -T to see the rake tasks defined

License

Copryright 2016 Juanma Rodriguez

This library is copyrighted software and it can be used and distributed as open source under the terms of the MIT License (as featured on opensource.org).

You can find the source code at https://github.com/jmrod4/miniparse.