2

Possible Duplicate:
Ruby OptionParser empty switch “-” behavior

I've wrote code that uses OptionParser to handle command line input gracefully. I am facing two major hits.

  1. Passing an empty switches '-' doesn't give an error.
  2. The program requires two mandatory switches, but it accepts one switch without complaining!

For the first case I've done this:

opts.on('-', '--') do |value|
  $stderr.print "Invalid empty switch"
  exit 1
end

EDIT (Jumped on success too soon): It works in the case of empty switch, but also if the switch is not empty. How can I do this?

For the second case, I've looked around for a solution within the OptionParser.new block but I couldn't find one. Doing it outside the OptionParser.new block is the normal way?

Community
  • 1
  • 1
ismail
  • 266
  • 2
  • 12

0 Answers0