[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

getoptlong question

Matt Rose

3/7/2006 2:38:00 PM

5 Answers

Tassilo Horn

3/7/2006 2:58:00 PM

0

Matt Rose <mattrose@folkwolf.net> writes:

> What am I missing?

GetoptLong::each as well as GetoptLong::get consume the options. After
the first opts.each{..} your opts are emtpy.

The docs don't mention that, I think. I also had those troubles when I
used opts.get == nil to check if no options were given.

Perhaps you should have a look at the optparse module in the stdlib.

Regards,
Tassilo

Robert Klemme

3/7/2006 3:03:00 PM

0

>
2006/3/7, Matt Rose <mattrose@folkwolf.net>:
>
> This has been bugging me for weeks now, intermittently.
>
> By all accounts I've read, this getoptlong code should work
>
> require 'getoptlong'
>
> opts = GetoptLong.new(
> ["--devel","-d",GetoptLong::NO_ARGUMENT],
> ["--getpass","-g",GetoptLong::NO_ARGUMENT],
> ["--debug","-D",GetoptLong::NO_ARGUMENT],
> ["--verbose","-V",GetoptLong::NO_ARGUMENT]
> )
>
> server = 'http://192.168.1...
> verbose = false
> opts.each { |o,a| p o }
> opts.each { |o,a|
> case o
> when '--devel'
> server = 'http://192.168.2...
> when '--getpass'
> puts "this option does nothing"
> when '--debug': $DEBUG = true
> when '--verbose': verbose = true
> end
> }
> p server
> p $DEBUG
> p verbose
>
> This is the output I expect when I run it:
>
> "--devel"
> "--debug"
> "--verbose"
> "http://192.168.20...
> true
> true
>
> This is the output I get:
>
> "--devel"
> "--debug"
> "--verbose"
> "http://192.168.10...
> false
> false
>
> What am I missing?

Insert a "p a" in the second opts.each block and see what happens. :-)

Kind regards

robert


--
Have a look: http://www.flickr.com/photos/fu...


Ara.T.Howard

3/7/2006 3:05:00 PM

0

Matt Rose

3/7/2006 3:22:00 PM

0

Ara.T.Howard

3/7/2006 3:31:00 PM

0