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.
- Passing an empty switches '-' doesn't give an error.
- 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?