From: Daniel Berger Date: 2005-11-05T03:42:14+09:00 Subject: [ANN] getopt-1.3.0 Hi all, I'm pleased to announce the release of getopt-1.3.0. This release includes a Getopt::Long class. == What is it? A sane replacement for command line parsing libraries like getoptlong and optparse. == How does it work It's similar to the old Getoptlong class, but it's less verbose, more flexible and (*shock*) it returns a hash. == Synopsis require "getopt/long" include Getopt opts = Long.getopts( [ "--name", "-n", REQUIRED ], [ "--age", "-a", OPTIONAL ], [ "--more", "-m", INCREMENT], [ "--verbose", "-v", BOOLEAN] ) # User passes "--name dan --age=35 -m -m -v" opts == { "n" => "dan", "name" => "dan", "a" => "35", "age" => "35", "m" => 2, "more" => 2, "v" => true, "verbose" => true } The dups are there to give you maximum flexibility with regards to how you access your option, e.g. you could do: if opts["v"] # or if opts["verbose"] This, along with the removal of "--" and "-", saves on the carpal. You'll also notice that you can use the "=" syntax for long options, e.g. "--age=35", if you happen to prefer that style. See the README file for more details. == Where can I get it? You should be able to do "gem install getopt" very soon. Or, you can get the tarball via the RAA. == Why I wrote this My main gripe with the getoptlong library currently in the standard library is that it doesn't return a hash, yet gives you partial hash behavior. This was both confusing and annoying, since the first thing I (and everyone else) does is collect the results into a hash for later processing. Just yesterday Ara Howard did this in ruby-talk:163940. It's also too verbose. My main gripe with the optparse library (also in the standard library) is that it treats command line processing like event processing. It's too complex, when 90% of the time all you want to do is slurp the command line options into a hash. So, I did something utterly novel with this library. I collected the command line options ... (wait for it) ... into a hash! Then I give that hash to you, aliases and all. I did get some ideas from Perl's Getopt::Long library, but this is in no way a port of that module (which supports POSIX parsing, GNU parsing, more option types, etc). My goal was to provide the functionality that I felt would cover the vast majority of common cases, yet still provide a little extra spice with switch types (REQUIRED, OPTIONAL, etc). == Future Plans There are a few extra things I plan to add but I do not plan on this library ever becoming as feature rich as, say, Perl's Getopt::Long module. I'm more interested in just making it usable and easy. Enjoy! Dan