> A "mandatory option" is a contradiction :)  You need to test for the
> presence of an option in your own code.

This is a fair point, but for complex command lines we sometimes really 
need options that are not optional. For example, I'm working on a ruby 
xmltv-like scraper, that has a bunch of regular options, plus essential 
arguments like --config CONFIG_FILE and --scraper SCRAPER_FILE for 
specifying files that are necessary.

I want to use options for these rather than arguments because they are 
both files and I prefer that the user specify the option --config or 
--scraper rather than having to get the order of them right on the 
command line.

So you see, I need an "option" that is mandatory in addition to it 
having a mandatory argument.

Sure I could do it in my own code - but given this is a common case I'm 
tempted to extend OptionParser to do it so that I can get at the option 
description when I report that its missing you see? This is why it 
should probably be a feature of OptionParser - to tie the error message 
to the switch that's missing. I don't think I can be bothered wading 
into that code myself, so I guess I'll do something a little hackier - 
test my options and repeat the option descriptions.

But how about it Gavin?

Also -  even if you don't  - you should probably clearly document the 
fact this isn't available. The frequent use of "MANDATORY" in the 
example led me and probably many others to think it was bug that my 
mandatory arguments weren't reported as missing. It took me a while to 
realize that the word "argument" was key here. It also took me a while 
to realize that the square brackets were important.

-- 
Posted via http://www.ruby-forum.com/.