Thrill
0.1
|
Command line parser which automatically fills variables and prints nice usage messages.
This is a straightforward command line parser in C++, which will recognize short options -s, long options –long and parameters, both required and optional. It will automatically parse integers and byte sizes with SI/IEC suffixes (e.g. 1 GiB). It also works with lists of strings, e.g. multiple filenames.
When running the program above without arguments, it will print:
$ ./tlx_cmdline_parser_example Missing required argument for parameter 'filename' Usage: ./tlx_cmdline_parser_example [options] <filename> This may some day be a useful program, which solves many serious problems of the real world and achives global peace. Author: Timo Bingmann <[email protected]> Parameters: filename A filename to process Options: -r, --rounds N Run N rounds of the experiment. -s, --size Number of bytes to process.
Nice output, notice the line wrapping of the description and formatting of parameters and arguments. These too are wrapped if the description is too long.
We now try to give the program some arguments:
$ ./tlx_cmdline_parser_example -s 2GiB -r 42 /dev/null Option -s, --size set to 2147483648. Option -r, --rounds N set to 42. Parameter filename set to "/dev/null". Command line parsed okay. Parameters: filename (string) "/dev/null" Options: -r, --rounds N (unsigned integer) 42 -s, --size (bytes) 2147483648
The output shows pretty much what happens. The command line parser is by default in a verbose mode outputting all arguments and values parsed. The debug summary shows to have values the corresponding variables were set.
One feature worth naming is that the parser also supports lists of strings, i.e. std::vector<std::string>
via CmdlineParser::add_param_stringlist() and similar.
Definition at line 77 of file cmdline_parser.hpp.
#include <cmdline_parser.hpp>
Public Member Functions | |
CmdlineParser () | |
Constructor. More... | |
~CmdlineParser () | |
Delete all added arguments. More... | |
void | print_result (std::ostream &os) |
print nicely formatted result of processing More... | |
void | print_result () |
print nicely formatted result of processing to std::cout More... | |
void | print_usage (std::ostream &os) |
void | print_usage () |
bool | process (int argc, const char *const *argv, std::ostream &os) |
bool | process (int argc, const char *const *argv) |
void | set_author (const std::string &author) |
Set author of program, will be wrapped. More... | |
void | set_description (const std::string &description) |
Set description of program, text will be wrapped. More... | |
void | set_verbose_process (bool verbose_process) |
Set verbose processing of command line arguments. More... | |
CmdlineParser & | sort () |
sort options by key (but not the positional parameters) More... | |
Add Option with short -k, --longkey, and description. | |
void | add_bool (char key, const std::string &longkey, bool &dest, const std::string &desc) |
void | add_flag (char key, const std::string &longkey, bool &dest, const std::string &desc) |
void | add_int (char key, const std::string &longkey, int &dest, const std::string &desc) |
void | add_unsigned (char key, const std::string &longkey, unsigned int &dest, const std::string &desc) |
void | add_uint (char key, const std::string &longkey, unsigned int &dest, const std::string &desc) |
void | add_size_t (char key, const std::string &longkey, size_t &dest, const std::string &desc) |
add size_t option -key, –longkey with description and store to dest More... | |
void | add_float (char key, const std::string &longkey, float &dest, const std::string &desc) |
add float option -key, –longkey with description and store to dest More... | |
void | add_double (char key, const std::string &longkey, double &dest, const std::string &desc) |
add double option -key, –longkey with description and store to dest More... | |
void | add_bytes (char key, const std::string &longkey, uint32_t &dest, const std::string &desc) |
void | add_bytes (char key, const std::string &longkey, uint64_t &dest, const std::string &desc) |
void | add_string (char key, const std::string &longkey, std::string &dest, const std::string &desc) |
add string option -key, –longkey and store to dest More... | |
void | add_stringlist (char key, const std::string &longkey, std::vector< std::string > &dest, const std::string &desc) |
add string list option -key, –longkey and store to dest More... | |
Add Option with --longkey and description. | |
void | add_bool (const std::string &longkey, bool &dest, const std::string &desc) |
add boolean option flag –longkey with description and store to dest More... | |
void | add_flag (const std::string &longkey, bool &dest, const std::string &desc) |
void | add_int (const std::string &longkey, int &dest, const std::string &desc) |
add signed integer option –longkey with description and store to dest More... | |
void | add_unsigned (const std::string &longkey, unsigned int &dest, const std::string &desc) |
add unsigned integer option –longkey with description and store to dest More... | |
void | add_uint (const std::string &longkey, unsigned int &dest, const std::string &desc) |
void | add_size_t (const std::string &longkey, size_t &dest, const std::string &desc) |
add size_t option –longkey with description and store to dest More... | |
void | add_float (const std::string &longkey, float &dest, const std::string &desc) |
add float option –longkey with description and store to dest More... | |
void | add_double (const std::string &longkey, double &dest, const std::string &desc) |
add double option –longkey with description and store to dest More... | |
void | add_bytes (const std::string &longkey, uint32_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option –longkey and store to 32-bit dest More... | |
void | add_bytes (const std::string &longkey, uint64_t &dest, const std::string &desc) |
add SI/IEC suffixes byte size option –longkey and store to 64-bit dest More... | |
void | add_string (const std::string &longkey, std::string &dest, const std::string &desc) |
add string option –longkey and store to dest More... | |
void | add_stringlist (const std::string &longkey, std::vector< std::string > &dest, const std::string &desc) |
add string list option –longkey and store to dest More... | |
Add Option with short -k, --longkey, [keytype], and description. | |
void | add_bool (char key, const std::string &longkey, const std::string &keytype, bool &dest, const std::string &desc) |
void | add_flag (char key, const std::string &longkey, const std::string &keytype, bool &dest, const std::string &desc) |
void | add_int (char key, const std::string &longkey, const std::string &keytype, int &dest, const std::string &desc) |
void | add_unsigned (char key, const std::string &longkey, const std::string &keytype, unsigned int &dest, const std::string &desc) |
void | add_uint (char key, const std::string &longkey, const std::string &keytype, unsigned int &dest, const std::string &desc) |
void | add_size_t (char key, const std::string &longkey, const std::string &keytype, size_t &dest, const std::string &desc) |
void | add_float (char key, const std::string &longkey, const std::string &keytype, float &dest, const std::string &desc) |
void | add_double (char key, const std::string &longkey, const std::string &keytype, double &dest, const std::string &desc) |
void | add_bytes (char key, const std::string &longkey, const std::string &keytype, uint32_t &dest, const std::string &desc) |
void | add_bytes (char key, const std::string &longkey, const std::string &keytype, uint64_t &dest, const std::string &desc) |
void | add_string (char key, const std::string &longkey, const std::string &keytype, std::string &dest, const std::string &desc) |
add string option -key, –longkey [keytype] and store to dest More... | |
void | add_stringlist (char key, const std::string &longkey, const std::string &keytype, std::vector< std::string > &dest, const std::string &desc) |
add string list option -key, –longkey [keytype] and store to dest More... | |
Add Required Parameter [name] with description. | |
void | add_param_int (const std::string &name, int &dest, const std::string &desc) |
add signed integer parameter [name] with description and store to dest More... | |
void | add_param_unsigned (const std::string &name, unsigned int &dest, const std::string &desc) |
add unsigned integer parameter [name] with description and store to dest More... | |
void | add_param_uint (const std::string &name, unsigned int &dest, const std::string &desc) |
void | add_param_size_t (const std::string &name, size_t &dest, const std::string &desc) |
add size_t parameter [name] with description and store to dest More... | |
void | add_param_float (const std::string &name, float &dest, const std::string &desc) |
add float parameter [name] with description and store to dest More... | |
void | add_param_double (const std::string &name, double &dest, const std::string &desc) |
add double parameter [name] with description and store to dest More... | |
void | add_param_bytes (const std::string &name, uint32_t &dest, const std::string &desc) |
void | add_param_bytes (const std::string &name, uint64_t &dest, const std::string &desc) |
void | add_param_string (const std::string &name, std::string &dest, const std::string &desc) |
add string parameter [name] with description and store to dest More... | |
void | add_param_stringlist (const std::string &name, std::vector< std::string > &dest, const std::string &desc) |
Add Optional Parameter [name] with description. | |
void | add_opt_param_int (const std::string &name, int &dest, const std::string &desc) |
void | add_opt_param_unsigned (const std::string &name, unsigned int &dest, const std::string &desc) |
void | add_opt_param_uint (const std::string &name, unsigned int &dest, const std::string &desc) |
void | add_opt_param_size_t (const std::string &name, size_t &dest, const std::string &desc) |
add optional size_t parameter [name] with description and store to dest More... | |
void | add_opt_param_float (const std::string &name, float &dest, const std::string &desc) |
add optional float parameter [name] with description and store to dest More... | |
void | add_opt_param_double (const std::string &name, double &dest, const std::string &desc) |
add optional double parameter [name] with description and store to dest More... | |
void | add_opt_param_bytes (const std::string &name, uint32_t &dest, const std::string &desc) |
void | add_opt_param_bytes (const std::string &name, uint64_t &dest, const std::string &desc) |
void | add_opt_param_string (const std::string &name, std::string &dest, const std::string &desc) |
add optional string parameter [name] with description and store to dest More... | |
void | add_opt_param_stringlist (const std::string &name, std::vector< std::string > &dest, const std::string &desc) |
Static Public Member Functions | |
static void | output_wrap (std::ostream &os, const std::string &text, size_t wraplen, size_t indent_first=0, size_t indent_rest=0, size_t current=0, size_t indent_newline=0) |
Private Types | |
using | ArgumentList = std::vector< Argument * > |
option and parameter list type More... | |
Private Member Functions | |
void | calc_option_max (const Argument *arg) |
update maximum formatting width for new option More... | |
void | calc_param_max (const Argument *arg) |
update maximum formatting width for new parameter More... | |
void | print_option_error (int argc, const char *const *argv, const Argument *arg, std::ostream &os) |
print error about option. More... | |
void | print_param_error (int argc, const char *const *argv, const Argument *arg, std::ostream &os) |
print error about parameter. More... | |
Private Attributes | |
std::string | author_ |
user set author of program, will be wrapped More... | |
std::string | description_ |
user set description of program, will be wrapped More... | |
unsigned int | line_wrap_ = 80 |
set line wrap length More... | |
ArgumentList | option_list_ |
list of options available More... | |
size_t | option_max_width_ = 8 |
formatting width for options, '-s, –switch <#>' More... | |
ArgumentList | param_list_ |
list of parameters, both required and optional More... | |
size_t | param_max_width_ = 8 |
formatting width for parameters, 'param <#>' More... | |
const char * | program_name_ = nullptr |
argv[0] for usage. More... | |
bool | verbose_process_ = false |
verbose processing of arguments More... | |
Static Private Attributes | |
static constexpr int | max_type_name_ = 16 |
maximum length of a type_name() result More... | |
|
private |
option and parameter list type
Definition at line 95 of file cmdline_parser.hpp.
CmdlineParser | ( | ) |
Constructor.
Definition at line 449 of file cmdline_parser.cpp.
~CmdlineParser | ( | ) |
Delete all added arguments.
Definition at line 451 of file cmdline_parser.cpp.
References CmdlineParser::option_list_, and CmdlineParser::param_list_.
void add_bool | ( | char | key, |
const std::string & | longkey, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey with description and store to dest
Definition at line 571 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_bool(), CmdlineParser::add_flag(), and main().
void add_bool | ( | const std::string & | longkey, |
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag –longkey with description and store to dest
Definition at line 634 of file cmdline_parser.cpp.
References CmdlineParser::add_bool().
void add_bool | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey [keytype] with description and store to dest
Definition at line 475 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey and store to 32-bit dest
Definition at line 611 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_bytes(), and main().
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey and store to 64-bit dest
Definition at line 616 of file cmdline_parser.cpp.
References CmdlineParser::add_bytes().
void add_bytes | ( | const std::string & | longkey, |
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option –longkey and store to 32-bit dest
Definition at line 674 of file cmdline_parser.cpp.
References CmdlineParser::add_bytes().
void add_bytes | ( | const std::string & | longkey, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option –longkey and store to 64-bit dest
Definition at line 679 of file cmdline_parser.cpp.
References CmdlineParser::add_bytes().
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest
Definition at line 535 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_bytes | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size option -key, –longkey [keytype] and store to 64-bit dest
Definition at line 543 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_double | ( | char | key, |
const std::string & | longkey, | ||
double & | dest, | ||
const std::string & | desc | ||
) |
add double option -key, –longkey with description and store to dest
Definition at line 606 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_double(), and main().
void add_double | ( | const std::string & | longkey, |
double & | dest, | ||
const std::string & | desc | ||
) |
add double option –longkey with description and store to dest
Definition at line 669 of file cmdline_parser.cpp.
References CmdlineParser::add_double().
void add_double | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
double & | dest, | ||
const std::string & | desc | ||
) |
add double option -key, –longkey [keytype] with description and store to dest
Definition at line 527 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_flag | ( | char | key, |
const std::string & | longkey, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey with description and store to dest. identical to add_bool()
Definition at line 576 of file cmdline_parser.cpp.
References CmdlineParser::add_bool().
Referenced by main().
void add_flag | ( | const std::string & | longkey, |
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag –longkey with description and store to dest. identical to add_bool()
Definition at line 639 of file cmdline_parser.cpp.
References CmdlineParser::add_bool().
void add_flag | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
bool & | dest, | ||
const std::string & | desc | ||
) |
add boolean option flag -key, –longkey [keytype] with description and store to dest. identical to add_bool()
Definition at line 483 of file cmdline_parser.cpp.
References CmdlineParser::add_bool().
void add_float | ( | char | key, |
const std::string & | longkey, | ||
float & | dest, | ||
const std::string & | desc | ||
) |
add float option -key, –longkey with description and store to dest
Definition at line 601 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_float().
void add_float | ( | const std::string & | longkey, |
float & | dest, | ||
const std::string & | desc | ||
) |
add float option –longkey with description and store to dest
Definition at line 664 of file cmdline_parser.cpp.
References CmdlineParser::add_float().
void add_float | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
float & | dest, | ||
const std::string & | desc | ||
) |
add float option -key, –longkey [keytype] with description and store to dest
Definition at line 519 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_int | ( | char | key, |
const std::string & | longkey, | ||
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer option -key, –longkey with description and store to dest
Definition at line 581 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_int().
void add_int | ( | const std::string & | longkey, |
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer option –longkey with description and store to dest
Definition at line 644 of file cmdline_parser.cpp.
References CmdlineParser::add_int().
void add_int | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer option -key, –longkey [keytype] with description and store to dest
Definition at line 489 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_opt_param_bytes | ( | const std::string & | name, |
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 800 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_bytes | ( | const std::string & | name, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add optional SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 807 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_double | ( | const std::string & | name, |
double & | dest, | ||
const std::string & | desc | ||
) |
add optional double parameter [name] with description and store to dest
Definition at line 793 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_float | ( | const std::string & | name, |
float & | dest, | ||
const std::string & | desc | ||
) |
add optional float parameter [name] with description and store to dest
Definition at line 787 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_int | ( | const std::string & | name, |
int & | dest, | ||
const std::string & | desc | ||
) |
add optional signed integer parameter [name] with description and store to dest
Definition at line 763 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_size_t | ( | const std::string & | name, |
size_t & | dest, | ||
const std::string & | desc | ||
) |
add optional size_t parameter [name] with description and store to dest
Definition at line 781 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_opt_param_string | ( | const std::string & | name, |
std::string & | dest, | ||
const std::string & | desc | ||
) |
add optional string parameter [name] with description and store to dest
Definition at line 814 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_opt_param_stringlist | ( | const std::string & | name, |
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add optional string parameter [name] with description and store to dest
Definition at line 821 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_opt_param_uint | ( | const std::string & | name, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add optional unsigned integer parameter [name] with description and store to dest. identical to add_unsigned()
Definition at line 776 of file cmdline_parser.cpp.
References CmdlineParser::add_opt_param_unsigned().
void add_opt_param_unsigned | ( | const std::string & | name, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add optional unsigned integer parameter [name] with description and store to dest
Definition at line 769 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by CmdlineParser::add_opt_param_uint().
void add_param_bytes | ( | const std::string & | name, |
uint32_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 733 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_param_bytes | ( | const std::string & | name, |
uint64_t & | dest, | ||
const std::string & | desc | ||
) |
add SI/IEC suffixes byte size parameter [name] with description and store to dest
Definition at line 740 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_param_double | ( | const std::string & | name, |
double & | dest, | ||
const std::string & | desc | ||
) |
add double parameter [name] with description and store to dest
Definition at line 727 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_param_float | ( | const std::string & | name, |
float & | dest, | ||
const std::string & | desc | ||
) |
add float parameter [name] with description and store to dest
Definition at line 721 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_param_int | ( | const std::string & | name, |
int & | dest, | ||
const std::string & | desc | ||
) |
add signed integer parameter [name] with description and store to dest
Definition at line 697 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
void add_param_size_t | ( | const std::string & | name, |
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t parameter [name] with description and store to dest
Definition at line 715 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_param_string | ( | const std::string & | name, |
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string parameter [name] with description and store to dest
Definition at line 747 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_param_stringlist | ( | const std::string & | name, |
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list parameter [name] with description and store to dest.
Definition at line 753 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by main().
void add_param_uint | ( | const std::string & | name, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer parameter [name] with description and store to dest. identical to add_unsigned()
Definition at line 710 of file cmdline_parser.cpp.
References CmdlineParser::add_param_unsigned().
void add_param_unsigned | ( | const std::string & | name, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer parameter [name] with description and store to dest
Definition at line 703 of file cmdline_parser.cpp.
References CmdlineParser::calc_param_max(), and CmdlineParser::param_list_.
Referenced by CmdlineParser::add_param_uint(), and main().
void add_size_t | ( | char | key, |
const std::string & | longkey, | ||
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t option -key, –longkey with description and store to dest
Definition at line 596 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_size_t(), and main().
void add_size_t | ( | const std::string & | longkey, |
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t option –longkey with description and store to dest
Definition at line 659 of file cmdline_parser.cpp.
References CmdlineParser::add_size_t().
void add_size_t | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
size_t & | dest, | ||
const std::string & | desc | ||
) |
add size_t option -key, –longkey [keytype] with description and store to dest
Definition at line 511 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_string | ( | char | key, |
const std::string & | longkey, | ||
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string option -key, –longkey and store to dest
Definition at line 621 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_string(), and main().
void add_string | ( | const std::string & | longkey, |
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string option –longkey and store to dest
Definition at line 684 of file cmdline_parser.cpp.
References CmdlineParser::add_string().
void add_string | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
std::string & | dest, | ||
const std::string & | desc | ||
) |
add string option -key, –longkey [keytype] and store to dest
Definition at line 551 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_stringlist | ( | char | key, |
const std::string & | longkey, | ||
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list option -key, –longkey and store to dest
Definition at line 626 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_stringlist().
void add_stringlist | ( | const std::string & | longkey, |
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list option –longkey and store to dest
Definition at line 689 of file cmdline_parser.cpp.
References CmdlineParser::add_stringlist().
void add_stringlist | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
std::vector< std::string > & | dest, | ||
const std::string & | desc | ||
) |
add string list option -key, –longkey [keytype] and store to dest
Definition at line 559 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
void add_uint | ( | char | key, |
const std::string & | longkey, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey with description and store to dest. identical to add_unsigned()
Definition at line 591 of file cmdline_parser.cpp.
References CmdlineParser::add_unsigned().
void add_uint | ( | const std::string & | longkey, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option –longkey with description and store to dest. identical to add_unsigned()
Definition at line 654 of file cmdline_parser.cpp.
References CmdlineParser::add_unsigned().
void add_uint | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest. identical to add_unsigned()
Definition at line 505 of file cmdline_parser.cpp.
References CmdlineParser::add_unsigned().
void add_unsigned | ( | char | key, |
const std::string & | longkey, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey with description and store to dest
Definition at line 586 of file cmdline_parser.cpp.
Referenced by CmdlineParser::add_uint(), CmdlineParser::add_unsigned(), and main().
void add_unsigned | ( | const std::string & | longkey, |
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option –longkey with description and store to dest
Definition at line 649 of file cmdline_parser.cpp.
References CmdlineParser::add_unsigned().
void add_unsigned | ( | char | key, |
const std::string & | longkey, | ||
const std::string & | keytype, | ||
unsigned int & | dest, | ||
const std::string & | desc | ||
) |
add unsigned integer option -key, –longkey [keytype] with description and store to dest
Definition at line 497 of file cmdline_parser.cpp.
References CmdlineParser::calc_option_max(), and CmdlineParser::option_list_.
|
private |
update maximum formatting width for new option
Definition at line 396 of file cmdline_parser.cpp.
References max(), and CmdlineParser::option_max_width_.
Referenced by CmdlineParser::add_bool(), CmdlineParser::add_bytes(), CmdlineParser::add_double(), CmdlineParser::add_float(), CmdlineParser::add_int(), CmdlineParser::add_size_t(), CmdlineParser::add_string(), CmdlineParser::add_stringlist(), and CmdlineParser::add_unsigned().
|
private |
update maximum formatting width for new parameter
Definition at line 401 of file cmdline_parser.cpp.
References max(), and CmdlineParser::param_max_width_.
Referenced by CmdlineParser::add_opt_param_bytes(), CmdlineParser::add_opt_param_double(), CmdlineParser::add_opt_param_float(), CmdlineParser::add_opt_param_int(), CmdlineParser::add_opt_param_size_t(), CmdlineParser::add_opt_param_string(), CmdlineParser::add_opt_param_stringlist(), CmdlineParser::add_opt_param_unsigned(), CmdlineParser::add_param_bytes(), CmdlineParser::add_param_double(), CmdlineParser::add_param_float(), CmdlineParser::add_param_int(), CmdlineParser::add_param_size_t(), CmdlineParser::add_param_string(), CmdlineParser::add_param_stringlist(), and CmdlineParser::add_param_unsigned().
|
static |
Wrap a long string at spaces into lines. Prefix is added unconditionally to each line. Lines are wrapped after wraplen characters if possible.
Definition at line 408 of file cmdline_parser.cpp.
Referenced by CmdlineParser::print_usage().
|
private |
print error about option.
Definition at line 901 of file cmdline_parser.cpp.
References CmdlineParser::print_usage().
Referenced by CmdlineParser::process().
|
private |
print error about parameter.
Definition at line 914 of file cmdline_parser.cpp.
References CmdlineParser::print_usage().
Referenced by CmdlineParser::process().
void print_result | ( | std::ostream & | os | ) |
print nicely formatted result of processing
Definition at line 1073 of file cmdline_parser.cpp.
References max(), CmdlineParser::max_type_name_, CmdlineParser::option_list_, CmdlineParser::option_max_width_, CmdlineParser::param_list_, and CmdlineParser::param_max_width_.
Referenced by main().
void print_result | ( | ) |
print nicely formatted result of processing to std::cout
Definition at line 1119 of file cmdline_parser.cpp.
void print_usage | ( | std::ostream & | os | ) |
output nicely formatted usage information including description of all parameters and options.
Definition at line 839 of file cmdline_parser.cpp.
References CmdlineParser::author_, CmdlineParser::description_, CmdlineParser::line_wrap_, CmdlineParser::option_list_, CmdlineParser::option_max_width_, CmdlineParser::output_wrap(), CmdlineParser::param_list_, CmdlineParser::param_max_width_, and CmdlineParser::program_name_.
void print_usage | ( | ) |
output to std::cout nicely formatted usage information including description of all parameters and options.
Definition at line 897 of file cmdline_parser.cpp.
Referenced by CmdlineParser::print_option_error(), CmdlineParser::print_param_error(), and CmdlineParser::process().
bool process | ( | int | argc, |
const char *const * | argv, | ||
std::ostream & | os | ||
) |
parse command line options as specified by the options and parameters added.
Definition at line 927 of file cmdline_parser.cpp.
References CmdlineParser::option_list_, CmdlineParser::param_list_, CmdlineParser::print_option_error(), CmdlineParser::print_param_error(), CmdlineParser::print_usage(), CmdlineParser::program_name_, and CmdlineParser::verbose_process_.
Referenced by main(), and CmdlineParser::process().
bool process | ( | int | argc, |
const char *const * | argv | ||
) |
parse command line options as specified by the options and parameters added.
Definition at line 1069 of file cmdline_parser.cpp.
References CmdlineParser::process().
void set_author | ( | const std::string & | author | ) |
Set author of program, will be wrapped.
Definition at line 465 of file cmdline_parser.cpp.
References CmdlineParser::author_.
Referenced by main().
void set_description | ( | const std::string & | description | ) |
Set description of program, text will be wrapped.
Definition at line 461 of file cmdline_parser.cpp.
References CmdlineParser::description_.
Referenced by main().
void set_verbose_process | ( | bool | verbose_process | ) |
Set verbose processing of command line arguments.
Definition at line 469 of file cmdline_parser.cpp.
References CmdlineParser::verbose_process_.
Referenced by main().
CmdlineParser & sort | ( | ) |
sort options by key (but not the positional parameters)
Definition at line 831 of file cmdline_parser.cpp.
References CmdlineParser::option_list_.
|
private |
user set author of program, will be wrapped
Definition at line 116 of file cmdline_parser.hpp.
Referenced by CmdlineParser::print_usage(), and CmdlineParser::set_author().
|
private |
user set description of program, will be wrapped
Definition at line 114 of file cmdline_parser.hpp.
Referenced by CmdlineParser::print_usage(), and CmdlineParser::set_description().
|
private |
set line wrap length
Definition at line 119 of file cmdline_parser.hpp.
Referenced by CmdlineParser::print_usage().
|
staticprivate |
maximum length of a type_name() result
Definition at line 122 of file cmdline_parser.hpp.
Referenced by CmdlineParser::print_result().
|
private |
list of options available
Definition at line 98 of file cmdline_parser.hpp.
Referenced by CmdlineParser::add_bool(), CmdlineParser::add_bytes(), CmdlineParser::add_double(), CmdlineParser::add_float(), CmdlineParser::add_int(), CmdlineParser::add_size_t(), CmdlineParser::add_string(), CmdlineParser::add_stringlist(), CmdlineParser::add_unsigned(), CmdlineParser::print_result(), CmdlineParser::print_usage(), CmdlineParser::process(), CmdlineParser::sort(), and CmdlineParser::~CmdlineParser().
|
private |
formatting width for options, '-s, –switch <#>'
Definition at line 103 of file cmdline_parser.hpp.
Referenced by CmdlineParser::calc_option_max(), CmdlineParser::print_result(), and CmdlineParser::print_usage().
|
private |
list of parameters, both required and optional
Definition at line 100 of file cmdline_parser.hpp.
Referenced by CmdlineParser::add_opt_param_bytes(), CmdlineParser::add_opt_param_double(), CmdlineParser::add_opt_param_float(), CmdlineParser::add_opt_param_int(), CmdlineParser::add_opt_param_size_t(), CmdlineParser::add_opt_param_string(), CmdlineParser::add_opt_param_stringlist(), CmdlineParser::add_opt_param_unsigned(), CmdlineParser::add_param_bytes(), CmdlineParser::add_param_double(), CmdlineParser::add_param_float(), CmdlineParser::add_param_int(), CmdlineParser::add_param_size_t(), CmdlineParser::add_param_string(), CmdlineParser::add_param_stringlist(), CmdlineParser::add_param_unsigned(), CmdlineParser::print_result(), CmdlineParser::print_usage(), CmdlineParser::process(), and CmdlineParser::~CmdlineParser().
|
private |
formatting width for parameters, 'param <#>'
Definition at line 105 of file cmdline_parser.hpp.
Referenced by CmdlineParser::calc_param_max(), CmdlineParser::print_result(), and CmdlineParser::print_usage().
|
private |
argv[0] for usage.
Definition at line 108 of file cmdline_parser.hpp.
Referenced by CmdlineParser::print_usage(), and CmdlineParser::process().
|
private |
verbose processing of arguments
Definition at line 111 of file cmdline_parser.hpp.
Referenced by CmdlineParser::process(), and CmdlineParser::set_verbose_process().