GetoptLong bug?

D

Daniel Berger

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
 
T

ts

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 :

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

Stefan Lang

Daniel said:
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}"
}
 
D

Daniel Berger

ts said:
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 :

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
 

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

GetoptLong usage 2
getoptlong question 5
GetoptLong#.quiet not doing what expected 2
About GetoptLong and exceptions 2
hash 13
hash 6
printing from a file - beginner 0
GetoptLong order of options 3

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top