[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

GetoptLong bug?

djberg96

3/8/2005 4:57:00 PM

Hi all,

Ruby 1.8.2
Solaris 9 and Windows XP Pro

If I have this:

# opt_test.rb
require "getoptlong"

opts = GetoptLong.new(
["--test", "-t", GetoptLong::REQUIRED_ARGUMENT]
)

puts "Done"

And then I run this:

> ruby opt_test.rb

or this:

> ruby opt_test.rb -t

Shouldn't a MissingArgument error be raised in both cases?

Regards,

Dan

3 Answers

ts

3/8/2005 5:17:00 PM

0

>>>>> "D" == Daniel Berger <djberg96@hotmail.com> writes:

D> opts = GetoptLong.new(
D> ["--test", "-t", GetoptLong::REQUIRED_ARGUMENT]
D> )

This mean that if you give the option --test then an argument is required,
but it will not give an error if -t is not given.

D> puts "Done"

Now you don't try to retrieve the options, this is why it don't give an
error in this case :

>> ruby opt_test.rb -t

call #each_option (or #get) and it will give the error.


--

Guy Decoux

Stefan Lang

3/8/2005 6:02:00 PM

0

Daniel Berger wrote:

> Hi all,
>
> Ruby 1.8.2
> Solaris 9 and Windows XP Pro
>
> If I have this:
>
> # opt_test.rb
> require "getoptlong"
>
> opts = GetoptLong.new(
> ["--test", "-t", GetoptLong::REQUIRED_ARGUMENT]
> )

Try to insert this:

opts.each { |opt, value|
puts "#{opt} has value #{value}"
}


>
> puts "Done"
>
> And then I run this:
>
>> ruby opt_test.rb
>
> or this:
>
>> ruby opt_test.rb -t
>
> Shouldn't a MissingArgument error be raised in both cases?
>
> Regards,
>
> Dan

djberg96

3/8/2005 7:35:00 PM

0

ts wrote:
> >>>>> "D" == Daniel Berger <djberg96@hotmail.com> writes:
>
> D> opts = GetoptLong.new(
> D> ["--test", "-t", GetoptLong::REQUIRED_ARGUMENT]
> D> )
>
> This mean that if you give the option --test then an argument is
required,
> but it will not give an error if -t is not given.
>
> D> puts "Done"
>
> Now you don't try to retrieve the options, this is why it don't give
an
> error in this case :
>
> >> ruby opt_test.rb -t
>
> call #each_option (or #get) and it will give the error.

Ah, I thought there was a way to force it to choke before this.
Thanks.

Dan