GetOptions - Yet another command line argument parser for Ruby. Inspired
by Perl’s Getopt::Long module, the GetOptions module provides a fairly
powerful POSIX-ish option parser that is very easy to learn and use.
http://rubyforge.org/projects/getoptions/
A quick and dirty example…
$ cat example.rb
require ‘getoptions’
opt = GetOptions.new(%w(help debug! verbose+ prefix:s size=i
host=@s))
p opt
–
$ ./example.rb --help
:help: true
$ ./example.rb --debug
:debug: true
$ ./example.rb --no-debug
:debug: false
$ ./example.rb -vvvvv
:verbose: 5
$ ./example.rb -vv --verbose
:verbose: 3
$ ./example.rb --pre
:prefix: nil
$ ./example.rb --pre myprefix
:prefix: “myprefix”
$ ./example.rb --size 5
:size: 5
$ ./example.rb --host foo bar baz
:host: [“foo”, “bar”, “baz”]
Give it a whirl and let me know what you think.
Enjoy,
Delaney