Protocol++® (Protocolpp®)
v5.6.2
|
Describes an option, its help text (usage) and how it should be parsed. More...
#include <optionparser.h>
Public Attributes | |
const unsigned | index |
Index of this option's linked list in the array filled in by the parser. More... | |
const int | type |
Used to distinguish between options with the same Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers. See Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers for details. More... | |
const char *const | shortopt |
Each char in this string will be accepted as a short option character. More... | |
const char *const | longopt |
The long option name (without the leading – ). More... | |
const CheckArg | check_arg |
For each option that matches shortopt or longopt this function will be called to check a potential argument to the option. More... | |
const char * | help |
The usage text associated with the options in this Descriptor. More... | |
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.
const CheckArg option::Descriptor::check_arg |
For each option that matches shortopt or longopt this function will be called to check a potential argument to the option.
This function will be called even if there is no potential argument. In that case it will be passed NULL
as arg
parameter. Do not confuse this with the empty string.
See CheckArg for more information.
const char* option::Descriptor::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 option::Descriptor::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 index
.
If you have options that mean exactly opposite things (e.g. –enable-foo
and –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 option::Descriptor::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 Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers 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. Parser::error()==true
. check_arg
does not return ARG_ILLEGAL the descriptor's Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers will be used to pick the linked list into which to put the unknown option. const char* const option::Descriptor::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 option::Descriptor::type |
Used to distinguish between options with the same Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers. See Protocol++® (ProtocolPP®) Protocol, Encryption, and Authentication Library with Testbench and Drivers for details.
It is recommended that you use an enum rather than a plain int to make your code more readable.