WvStreams
|
WvArgs - Sane command-line argument processing for WvStreams. More...
#include <wvargs.h>
Public Types | |
enum | flags_t { NO_EXIT_ON_ERRORS, FLAGS_SIZE } |
These flags control the behaviour of WvArgs. More... | |
typedef wv::function< bool(void *)> | NoArgCallback |
The callback type used for switches that do not take a parameter. More... | |
typedef wv::function< bool(WvStringParm, void *)> | ArgCallback |
The callback type used for switches that take a parameter It returns true if the switch was parsed correctly. | |
Public Member Functions | |
bool | process (int argc, char **argv, WvStringList *remaining_args=NULL) |
Process the command line arguments passed to main() using the options provided through calls to add_option(..). More... | |
void | set_version (WvStringParm version) |
Set the –version string. | |
void | set_email (WvStringParm email) |
Set the e-mail address for bug reports. | |
void | set_help_header (WvStringParm header) |
Set the introductory help message, printed at the beginning of –help. | |
void | set_help_footer (WvStringParm footer) |
Set the descriptive help message, printed at the end of –help. | |
void | print_usage (int argc, char **argv) |
Output the short usage message based on the provided options. More... | |
void | print_help (int argc, char **argv) |
Output the long usage message based on the provided options. | |
void | add_set_bool_option (char short_option, WvStringParm long_option, WvStringParm desc, bool &val) |
Add a boolean option, which, when specified, sets the specified boolean variable to true. More... | |
void | add_reset_bool_option (char short_option, WvStringParm long_option, WvStringParm desc, bool &val) |
Add a boolean option, which, when spefied, sets the specified boolean variable to false. More... | |
void | add_flip_bool_option (char short_option, WvStringParm long_option, WvStringParm desc, bool &val) |
Add a boolean option, which, when spefied, changes the value of the boolean variable from false to true or from true to false. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, int &val) |
Add a switch that takes an integer argument. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, long &val) |
Add a switch that takes a long argument. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, float &val) |
Add a switch that takes a float argument. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, double &val) |
Add a switch that takes a double argument. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, WvString &val) |
Add a switch that takes a string argument. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, WvStringList &val) |
Add a switch that takes a string argument; the argument is appended to a string list. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, NoArgCallback cb, void *ud=NULL) |
Add a switch which does not take an argument which invokes a callback when it is specified. More... | |
void | add_option (char short_option, WvStringParm long_option, WvStringParm desc, WvStringParm arg_desc, ArgCallback cb, void *ud=NULL) |
Add a switch which takes an argument which invokes a callback when it is specified. More... | |
void | add_required_arg (WvStringParm desc, bool multiple=false) |
Add a required argument to the list of parameters. More... | |
void | add_optional_arg (WvStringParm desc, bool multiple=false) |
Add an optional argument to the list of parameters. More... | |
void | remove_option (char short_option) |
Remove an option by specifying its short form. More... | |
void | remove_option (WvStringParm long_option) |
Remove an option by specifying its long form. More... | |
void | remove_all_options () |
Remove all options. | |
void | zap () |
An alias for remove_all_options() | |
bool | get_flag (const flags_t flag) const |
Get and set flags. | |
void | set_flag (const flags_t flag, const bool value) |
WvArgs - Sane command-line argument processing for WvStreams.
WvArgs allows you to specify a series of typed or callback-enabled command-line arguments. Once all of these arguments are specified, the WvArgs::process(..) function can be called to perform the actual argument processing.
Sample usage:
!
typedef wv::function<bool(void*)> WvArgs::NoArgCallback |
enum WvArgs::flags_t |
bool WvArgs::process | ( | int | argc, |
char ** | argv, | ||
WvStringList * | remaining_args = NULL |
||
) |
Process the command line arguments passed to main() using the options provided through calls to add_option(..).
If remaining_args is provided, any remaining arguments after the command line switches will be appended to this list.
Definition at line 784 of file wvargs.cc.
Referenced by WvDaemon::run().
void WvArgs::print_usage | ( | int | argc, |
char ** | argv | ||
) |
void WvArgs::add_set_bool_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
bool & | val | ||
) |
Add a boolean option, which, when specified, sets the specified boolean variable to true.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
val | The boolean variable to set to true when the switch is specified |
void WvArgs::add_reset_bool_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
bool & | val | ||
) |
Add a boolean option, which, when spefied, sets the specified boolean variable to false.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
val | The boolean variable to set to false when the switch is specified |
void WvArgs::add_flip_bool_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
bool & | val | ||
) |
Add a boolean option, which, when spefied, changes the value of the boolean variable from false to true or from true to false.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
val | The boolean variable to change when the switch is specified |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
int & | val | ||
) |
Add a switch that takes an integer argument.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The integer varible that gets the value of the argument |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
long & | val | ||
) |
Add a switch that takes a long argument.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The long varible that gets the value of the argument |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
float & | val | ||
) |
Add a switch that takes a float argument.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The float varible that gets the value of the argument |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
double & | val | ||
) |
Add a switch that takes a double argument.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The double varible that gets the value of the argument |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
WvString & | val | ||
) |
Add a switch that takes a string argument.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The string varible that gets the value of the argument |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
WvStringList & | val | ||
) |
Add a switch that takes a string argument; the argument is appended to a string list.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
val | The string list to which the argument is appended |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
NoArgCallback | cb, | ||
void * | ud = NULL |
||
) |
Add a switch which does not take an argument which invokes a callback when it is specified.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
cb | The callback function to invoke when the switch is encountered |
ud | A generic userdata pointer to pass to the callback |
void WvArgs::add_option | ( | char | short_option, |
WvStringParm | long_option, | ||
WvStringParm | desc, | ||
WvStringParm | arg_desc, | ||
ArgCallback | cb, | ||
void * | ud = NULL |
||
) |
Add a switch which takes an argument which invokes a callback when it is specified.
short_option | The single-character version of the switch; 0 for none |
long_option | The full-word version of the switch; NULL for none |
desc | The description of the option; NULL for none |
arg_desc | The (short) description of the argument; NULL for none |
cb | The callback function to invoke when the switch is encountered |
ud | A generic userdata pointer to pass to the callback |
void WvArgs::add_required_arg | ( | WvStringParm | desc, |
bool | multiple = false |
||
) |
Add a required argument to the list of parameters.
WvArgs will return an error when run if it is not specified.
The | description of the parameter |
Definition at line 966 of file wvargs.cc.
Referenced by add_optional_arg().
void WvArgs::add_optional_arg | ( | WvStringParm | desc, |
bool | multiple = false |
||
) |
Add an optional argument to the list of parameters.
The | description of the parameter |
Definition at line 982 of file wvargs.cc.
References add_required_arg().
void WvArgs::remove_option | ( | char | short_option | ) |
void WvArgs::remove_option | ( | WvStringParm | long_option | ) |