The Lean Mean C++ Option Parser
Describes an option, its help text (usage) and how it should be parsed.
The main input when constructing an option::Parser is an array of Descriptors.
|Index of this option's linked list in the array filled in by the parser. |
|Used to distinguish between options with the same index. See index for details. |
|const char *const||shortopt|
|Each char in this string will be accepted as a short option character. |
|const char *const||longopt|
|The long option name (without the leading |
|For each option that matches shortopt or longopt this function will be called to check a potential argument to the option. |
|const char *||help|
|The usage text associated with the options in this Descriptor. |
This function will be called even if there is no potential argument. In that case it will be passed
arg parameter. Do not confuse this with the empty string.
See CheckArg for more information.
|const char* help|
The usage text associated with the options in this Descriptor.
You can use option::printUsage() to format your usage message based on the
help texts. You can use dummy Descriptors where shortopt and longopt are both the empty string to add text to the usage that is not related to a specific option.
See option::printUsage() for special formatting characters you can use in
help to get a column layout.
|const unsigned index|
Index of this option's linked list in the array filled in by the parser.
Command line options whose Descriptors have the same index will end up in the same linked list in the order in which they appear on the command line. If you have multiple long option aliases that refer to the same option, give their descriptors the same
If you have options that mean exactly opposite things (e.g.
--disable-foo ), you should also give them the same
index, but distinguish them through different values for type. That way they end up in the same list and you can just take the last element of the list and use its type. This way you get the usual behaviour where switches later on the command line override earlier ones without having to code it manually.
|const char* const longopt|
The long option name (without the leading
If this Descriptor should not have a long option name, use the empty string "". NULL is not permitted here!
While shortopt allows multiple short option characters, each Descriptor can have only a single long option name. If you have multiple long option names referring to the same option use separate Descriptors that have the same index and type. You may repeat short option characters in such an alias Descriptor but there's no need to.
'-'but starts with a minus character and does not match any Descriptor's shortopt or longopt.
check_argdoes not return ARG_ILLEGAL the descriptor's index will be used to pick the linked list into which to put the unknown option.
|const char* const shortopt|
Each char in this string will be accepted as a short option character.
The string must not include the minus character
'-' or you'll get undefined behaviour.
If this Descriptor should not have short option characters, use the empty string "". NULL is not permitted here!
See longopt for more information.
|const int type|