[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Check ARGV for option (what parser to use?

Boris Callens

7/2/2007 2:37:00 PM

Dear mailinglist,

Currently I'm eluded by the ARGV parser GetoptLong.
All the example show me the same structure that just itterates through
all the parsed flags and then overwrite a previously set standard value
when a certain case branch gets hit.

Am I completely wrong or is this a horrible way of doing things?

I would like for example to first check if a certain flag is set (--help
for example) before I get to setting and parsing values.

I would think that the parser creates a Hash table and that I could
acces it in this style:

if (opts[:help]) then
puts "some usage help"
else
parse all other values
end

Am I off track here?

regards
Boris

--
Posted via http://www.ruby-....

2 Answers

Ari Brown

7/2/2007 2:44:00 PM

0



On Jul 2, 2007, at 10:37 AM, Boris Callens wrote:
<snip>

I user CommandLine::OptionParser (gem), but there is also optparse.
You might have better luck with those.

-------------------------------------------|
Nietzsche is my copilot



Eli Bendersky

7/2/2007 2:50:00 PM

0

On Jul 2, 4:37 pm, Boris Callens <boris.callens....@fedex.com> wrote:
> Dear mailinglist,
>
> Currently I'm eluded by the ARGV parser GetoptLong.
> All the example show me the same structure that just itterates through
> all the parsed flags and then overwrite a previously set standard value
> when a certain case branch gets hit.
>
> Am I completely wrong or is this a horrible way of doing things?
>
> I would like for example to first check if a certain flag is set (--help
> for example) before I get to setting and parsing values.
>
> I would think that the parser creates a Hash table and that I could
> acces it in this style:
>
> if (opts[:help]) then
> puts "some usage help"
> else
> parse all other values
> end
>
> Am I off track here?
>

What really bothers you about the way GetoptLong works ? It seems to
me like an efficient and correct way to do things.

How can you check that --help is set without parsing the arguments ?

Although the documentation is (as usual) horrible, you can easily
understand how the module works by reading the code of the get()
function (it is used by 'each' under the hood).

Eli