[ANN] getopt-1.3.0

D

Daniel Berger

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
 
H

Hugh Sasse

Hi all,

I'm pleased to announce the release of getopt-1.3.0. This release includes a [...]
== 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"

Will one be able to write that as
-mmv --name dan --age=35
or not? I expect it makes parsing trickier. I don't do it for
single letter options that take parameters except
tar -cvf tarfile -
so I could live without it.

Thank you. Simplifying the interface is usually the right thing to
do :)

Thank you,
Hugh
 
D

Daniel Berger

Hugh Sasse wrote:

Will one be able to write that as
-mmv --name dan --age=35
or not? I expect it makes parsing trickier. I don't do it for
single letter options that take parameters except
tar -cvf tarfile -
so I could live without it.

Not at the moment, but it wouldn't be difficult to add it.
Thank you. Simplifying the interface is usually the right thing to
do :)

Thank you,
Hugh

You're welcome. :)

- Dan
 
D

Daniel Berger

Daniel said:
Hugh Sasse wrote:



Not at the moment, but it wouldn't be difficult to add it.

Good way to jinx myself, eh?

Anyway, you can do this as of 1.3.1, on the RAA now (and the gem should
be available shortly).

Regards,

Dan
 
S

sgbirch

Daniel said:
Hi all,

I'm pleased to announce the release of getopt-1.3.0. This release includes a
Getopt::Long class.

Now we need to get this into the standard libraries. :)

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] Slop 1.3.0 0
[ANN] win32console 1.3.0 Released 2
getopt 6
[ANN] win32console 1.3.0.beta2 Released 16
Command Line Arguments 0
[ANN] directory_watcher 1.3.0 0
[ANN] map-1.3.0 10
[ANN] mail Gem version 1.3.0 0

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top