[Tutor] Optparse question: if only certain values are acceptable

Terry Carroll carroll at tjc.com
Sat May 9 00:37:04 CEST 2009


I'm tryng to use optparse for the first time.

The toy summary is that I want to have the following command format:

  prognam -f FORMAT

Where FORMAT, if specified, must be one of "X", "Y", or "Z".

In otherwords, if the user enters:

 progname -f X

It runs, producing its output in format X.  Similar if "Y" or "Z" is
specified instead of "X".

But if the user specifies

 progname -f A

I want it to spit up because A is not a recognized format.

I don't see anything in the docs that directly addresses this.  Is this 
something that I should use the callback parameter for?



More information about the Tutor mailing list