Options PreviousNext

AP_OPTION is the common superclass of all options. It defines the fact that options can have a short and a long form and a descriptive text. It also can count the occurrences of an option and can mark the option as mandatory.

AP_OPTION_WITH_PARAMETER[G] extends AP_OPTION with the possibility of recoding parameters of type G. All options except for AP_FLAG inherit from this class.

Available option types

The following standard option types are available:

AP_FLAG
A simple flag that does not take an argument.
AP_STRING_OPTION
A flag that takes an arbitrary string as argument.
AP_BOOLEAN_OPTION
The flag needs to be supplied by a boolean value. The strings 'yes','y','1','true' and 't' are regarded as true. The strings 'no','n','0','false' and 'f' are regarded as false.
AP_ENUMERATION_OPTION
The enumeration options allows to choose one string out of a fixed set of choices. Available choices can be added to the option through the extend call.
AP_INTEGER_OPTION
This option takes an integer as an argument. Parsing will yield an error if no integer value is passed.
AP_DISPLAY_HELP_FLAG
This is a special flag to display a help message. It is normally added automatically through the call of make in AP_PARSER.

Defining own option types

It should be easy to implement own option types do define own parameters, for example for file names or dates. It is best to inherit form AP_OPTION_WITH_PARAMETER[G] or one of its decedents.

Options with optional parameters

Sometimes, mostly for backward compatibility, it is necessary to make the parameter to an option optional. This can be done by calling the set_parameter_as_optional feature in class AP_STRING_OPTION. To prevent the grammar from becoming ambiguous, this only works for long options. Also, it is impossible to use the space as a delimiter between option and parameter: '--foo=X' will parse as option foo with parameter 'X', '--foo X' will parse as foo without a parameter, and then the global parameter 'X'.

The parameters list in the option will record usages of the option without parameters as Void values.


Copyright 2001-2012, Bernd Schoeller
mailto:bernd@fams.de
http://www.gobosoft.com
Last Updated: 3 December 2012
HomeTocPreviousNext