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 a parameter.
AP_STRING_OPTION
A flag that takes an arbitrary string as parameter.
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 allow 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 parameter. 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 customized option types

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

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-2019, Bernd Schoeller
mailto:bernd@fams.de
http://www.gobosoft.com
Last Updated: 27 February 2019
HomeTocPreviousNext