From: "edward.og@..." Date: 2005-07-15T01:00:52+09:00 Subject: GetoptLong#.quiet not doing what expected (Writing this message for the second time - curse browsers for not saving the contents of input fields like these...) I'm a very beginner Ruby user. It's a pretty, poetic language. I'm using it to write a Nagios plugin. I took the synopsis that comes in the GetoptLong documentation, and turned on the quiet flag. ################################################################################ require 'getoptlong' # specify the options we accept and initialize # the option parser opts.quiet = true opts = GetoptLong.new( [ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--query", "-q", GetoptLong::NO_ARGUMENT ], [ "--check", "--valid", "-c", GetoptLong::NO_ARGUMENT ] ) # process the parsed options opts.each do |opt, arg| puts "Option: #{opt}, arg #{arg.inspect}" end puts "Remaining args: #{ARGV.join(', ')}" ################################################################################ The documentation says that the quiet flag makes the opt.each (in this case) stop when it reaches an invalid flag because GetoptLong#.get will have passed nil to the opts.each loop on reaching an invalid flag. I tried this: $ ruby getoptslongExample.rb -not -a -real -option getoptslongExample.rb: invalid option -- n /usr/lib/ruby/1.8/getoptlong.rb:265:in `set_error': invalid option -- n (GetoptLong::InvalidOption) from /usr/lib/ruby/1.8/getoptlong.rb:434:in `get_option' from /usr/lib/ruby/1.8/getoptlong.rb:458:in `each' from /usr/lib/ruby/1.8/getoptlong.rb:457:in `loop' from /usr/lib/ruby/1.8/getoptlong.rb:457:in `each' from getoptslongExample.rb:25 This doesn't look very quiet. I've caught the raised error with the following code: ################################################################################ #snip# # process the parsed options begin opts.each do |opt, arg| puts "Option: #{opt}, arg #{arg.inspect}" end rescue print "Chill, it's ok.\n" exit end ################################################################################ This works nicely, but I think I'd rather have the quiet version that I expected. Actually, what I really like to have is a version that could tell the user that *badOption* is invalid. How would I implement this, and why is the quiet option not doing anything? Thanks very much, Edward Ocampo-Gooding