Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
getopt-1.3.0
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Daniel Berger  
View profile  
 More options Nov 4 2005, 1:42 pm
Newsgroups: comp.lang.ruby
From: Daniel Berger <Daniel.Ber...@qwest.com>
Date: Sat, 5 Nov 2005 03:42:14 +0900
Local: Fri, Nov 4 2005 1:42 pm
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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Hugh Sasse  
View profile  
 More options Nov 4 2005, 2:01 pm
Newsgroups: comp.lang.ruby
From: Hugh Sasse <h...@dmu.ac.uk>
Date: Sat, 5 Nov 2005 04:01:55 +0900
Local: Fri, Nov 4 2005 2:01 pm
Subject: Re: [ANN] getopt-1.3.0

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Berger  
View profile  
 More options Nov 4 2005, 2:05 pm
Newsgroups: comp.lang.ruby
From: Daniel Berger <Daniel.Ber...@qwest.com>
Date: Sat, 5 Nov 2005 04:05:49 +0900
Local: Fri, Nov 4 2005 2:05 pm
Subject: Re: [ANN] getopt-1.3.0

Hugh Sasse wrote:

<snip>

>># 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.

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lou Vanek  
View profile  
 More options Nov 4 2005, 2:48 pm
Newsgroups: comp.lang.ruby
From: Lou Vanek <va...@acd.net>
Date: Sat, 5 Nov 2005 04:48:00 +0900
Subject: Re: [ANN] getopt-1.3.0
I believe CommandLine::OptionParser can do this
(http://rubyforge.org/docman/view.php/632/170/index.html).
Recommended.
-lv

Hugh Sasse wrote:

[snip]


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Berger  
View profile  
 More options Nov 18 2005, 10:28 am
Newsgroups: comp.lang.ruby
From: "Daniel Berger" <djber...@gmail.com>
Date: 18 Nov 2005 07:28:32 -0800
Local: Fri, Nov 18 2005 10:28 am
Subject: Re: getopt-1.3.0

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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sgbi...@gmail.com  
View profile  
 More options Nov 28 2005, 2:40 am
Newsgroups: comp.lang.ruby
From: sgbi...@gmail.com
Date: 27 Nov 2005 23:40:06 -0800
Local: Mon, Nov 28 2005 2:40 am
Subject: Re: getopt-1.3.0

Daniel Berger wrote:
> 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


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google