Optparser question

I am using optparser to parse arguments.How can I set a mandatory
option? If user doesn’t specify this option, parse() method should throw
an error message.

thanks,

Zhao Yi

2010/6/30 Zhao Yi [email protected]:

I am using optparser to parse arguments.How can I set a mandatory
option? If user doesn’t specify this option, parse() method should throw
an error message.

There are no mandatory options - after all, they are options. You
can only have mandatory arguments to options:

http://www.ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html

You need an extra flag which you set when the option is seen. Then you
can throw or do whatever after #parse has finished.

Kind regards

robert