Protocol++® (Protocolpp®)
v5.6.2
|
Functions for checking the validity of option arguments. More...
#include <optionparser.h>
Static Public Member Functions | |
static ArgStatus | None (const Option &, bool) |
For options that don't take an argument: Returns ARG_NONE. | |
static ArgStatus | Required (const option::Option &option, bool msg) |
Returns ARG_OK if the argument is supplied and ARG_ILLEGAL otherwise. | |
static ArgStatus | Optional (const Option &option, bool) |
Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise. | |
Functions for checking the validity of option arguments.
Every Option has such a function assigned in its Descriptor.
A CheckArg function has the following signature:
It is used to check if a potential argument would be acceptable for the option. It will even be called if there is no argument. In that case option.arg
will be NULL
.
If msg
is true
and the function determines that an argument is not acceptable and that this is a fatal error, it should output a message to the user before returning ARG_ILLEGAL. If msg
is false
the function should remain silent (or you will get duplicate messages).
See ArgStatus for the meaning of the return values.
While you can provide your own functions, often the following pre-defined checks (which never return ARG_ILLEGAL) will suffice:
Arg::None
For options that don't take an argument: Returns ARG_NONE. Arg::Optional
Returns ARG_OK if the argument is attached and ARG_IGNORE otherwise.The following example code can serve as starting place for writing your own more complex CheckArg functions: