From: nobu.nokada@... Date: 2004-01-17T10:18:06+09:00 Subject: Re: optparse and required arguments Hi, At Sat, 17 Jan 2004 09:12:14 +0900, E F van de Laar wrote: > I'm playing around with optparse and ran into something I couldn't get > working right off hand. I define two options; both of which require an > argument. I'm using a rescue clause "catch all" to catch options which > do not get an argument passed in. If I pass two of these on the command > line the second option gets passed as an argument to the first. Anyone > have an idea on how to get around this? If you want -L to get an argument only when next string doesn't seem an option, use "-L [LIB]". > require 'optparse' > > ARGV.options do |opts| opts.on("-L [LIB]", String) { |arg| puts "-L=#{arg.inspect}" } opts.on("-R [LIB]", String) { |arg| puts "-R=#{arg.inspect}" } > begin > opts.parse! > rescue > $stderr.puts "Error: #{$!}\n\n" + opts.to_s > exit 1 > end > end > > % ruby1.8 test.rb -L -R quux -L=nil -R="quux" -- Nobu Nakada