robertlafe... / comcast.net ha escrito:

> What is everyone using (other than manually) to process command line arguments?  I have looked at
> optparse (OptionParser) but it is not well documented.  Is there something better?  Or is there better
> documentation for optparse out there?

Getopt::Declare, for everything, since my good old Perl days, as
there's still nothing better.

Example:

#!/usr/bin/env ruby

require 'Getopt/Declare'

args = Getopt::Declare.new(<<'EOF')
  -q[uiet]               don't print status messages to stdout
                             but multi-line.  This allows something.
  -f[ile] <file:of>  write report to file
EOF

p args

# The example above makes it support -q, -quiet and -f, -file as output
file.
# -h[elp] and -v[ersion] come for free, too

How to get it:

http://rubyforge.org/projects/getoptdeclare/

or:

> gem install getopt-declare

Docs are not online (my fault, as they were long and rubyforge was
still in its infancy at the time).
Usage is almost identical to its Perl's cousin, so you can look at the
docs there.
The gem DOES ship with an rdoc file called Declare.rdoc, which
unfortunately rubygem's system still cannot 'ri' automatically, so you
need to 'ri' it manually.
Getopt-Declare uses a very complex parser behind the scenes, where you
just type in the help line description (all that getopt-declare needs).
 Don't be deceived by its simplicity (it has more features than any
other command-line parser).  It comes with a bunch of much more complex
demos in the samples directory of the gem distro.

The one gotcha, you just need a tab between your argument and your
description (at least until my next release, where I *finally* remove
that limitation and allow spaces, too)

PS.  I cannot take credit for Getopt/Declare, as it was something
Damian Conway came up many moons ago.  I just ported it to ruby and
fixed some bugs here and there.