The ArgParser class. For parsing command line arguments. More...
#include <zupply.hpp>
Public Member Functions | |
ArgParser () | |
ArgParser default constructor. | |
void | add_info (std::string info) |
Add info to parser. More... | |
ArgOption & | add_opt (char shortKey, std::string longKey) |
Add option. Use -1 for shortkey if you don't want to specify short key. Use "" for longkey if you don't want to specify long key. More... | |
ArgOption & | add_opt (char shortKey) |
Add option, short version only. More... | |
ArgOption & | add_opt (std::string longKey) |
Add option, long version only. More... | |
template<typename T > | |
ArgOption & | add_opt_value (char shortKey, std::string longKey, T &dst, T defaultValue, std::string help="", std::string type="", int min=1, int max=1) |
Template function for an option take a value. This will store the value from argument to dst, otherwise dst = defaultValue. More... | |
ArgOption & | add_opt_flag (char shortKey, std::string longKey, std::string help="", bool *dst=nullptr) |
Add an toggle option. When this option found, dst = true, otherwise dst = false. More... | |
void | add_opt_help (char shortKey, std::string longKey, std::string help="print this help and exit") |
Add a special option used to display help information for argument parser. When triggered, program will print help info and exit. More... | |
void | add_opt_version (char shortKey, std::string longKey, std::string version, std::string help="print version and exit") |
Add a special option used to display version information for argument parser. When triggered, program will print version info and exit. More... | |
std::string | version () const |
Return version info. More... | |
void | parse (int argc, char **argv, bool ignoreUnknown=false) |
Start parsing arguments. More... | |
std::size_t | count_error () |
Get error count generated during parsing. More... | |
int | count (char shortKey) |
Count the occurance of the option by short key. More... | |
int | count (std::string longKey) |
Count the occurance of the option by long key. More... | |
std::string | get_error () |
Get all errors generated during parsing. More... | |
std::string | get_help () |
Get help information of entire parser. More... | |
Value | operator[] (const std::string &longKey) |
Overloaded operator [] to retrieve the value by long key. More... | |
Value | operator[] (const char shortKey) |
Overloaded operator [] to retrieve the value by short key. More... | |
std::vector< Value > | arguments () const |
Return all input arguments that does not belong to any option. More... | |
Detailed Description
The ArgParser class. For parsing command line arguments.
Member Function Documentation
void zz::cfg::ArgParser::add_info | ( | std::string | info | ) |
Add info to parser.
- Parameters
-
info Info to add
ArgOption & zz::cfg::ArgParser::add_opt | ( | char | shortKey, |
std::string | longKey | ||
) |
Add option. Use -1 for shortkey if you don't want to specify short key. Use "" for longkey if you don't want to specify long key.
- Parameters
-
shortKey A char longKey A std::string
- Returns
- Reference to the added option
ArgOption & zz::cfg::ArgParser::add_opt | ( | char | shortKey | ) |
Add option, short version only.
- Parameters
-
shortKey A char
- Returns
- Reference to the added option
ArgOption & zz::cfg::ArgParser::add_opt | ( | std::string | longKey | ) |
Add option, long version only.
- Parameters
-
longKey A std::string
- Returns
- Reference to the added option
ArgOption & zz::cfg::ArgParser::add_opt_flag | ( | char | shortKey, |
std::string | longKey, | ||
std::string | help = "" , |
||
bool * | dst = nullptr |
||
) |
Add an toggle option. When this option found, dst = true, otherwise dst = false.
- Parameters
-
shortKey A char longKey A std::string help Help description. dst Pointer to a bool variable to be set accroding to this option.
- Returns
- Reference to the added option
void zz::cfg::ArgParser::add_opt_help | ( | char | shortKey, |
std::string | longKey, | ||
std::string | help = "print this help and exit" |
||
) |
Add a special option used to display help information for argument parser. When triggered, program will print help info and exit.
- Parameters
-
shortKey A char longKey A std::string help Option description
|
inline |
Template function for an option take a value. This will store the value from argument to dst, otherwise dst = defaultValue.
- Parameters
-
shortKey A char longKey A std::string dst Reference to the variable to be set defaultValue Default value if this option not found help Help description to this option type Help describe the type of this option min Minimum count of argument it takes max Maximum count of argument it takes, use -1 to allow unlimited arguments
- Returns
- Reference to the added option
void zz::cfg::ArgParser::add_opt_version | ( | char | shortKey, |
std::string | longKey, | ||
std::string | version, | ||
std::string | help = "print version and exit" |
||
) |
Add a special option used to display version information for argument parser. When triggered, program will print version info and exit.
- Parameters
-
shortKey A char longKey A std::string help Option description
std::vector< Value > zz::cfg::ArgParser::arguments | ( | ) | const |
Return all input arguments that does not belong to any option.
- Returns
- Arguments in vector
int zz::cfg::ArgParser::count | ( | char | shortKey | ) |
Count the occurance of the option by short key.
- Parameters
-
shortKey
- Returns
- Occurance count
int zz::cfg::ArgParser::count | ( | std::string | longKey | ) |
Count the occurance of the option by long key.
- Parameters
-
longKey
- Returns
- Occurance count
|
inline |
Get error count generated during parsing.
- Returns
- Number of errors generated.
std::string zz::cfg::ArgParser::get_error | ( | ) |
Get all errors generated during parsing.
- Returns
- Errors in string
std::string zz::cfg::ArgParser::get_help | ( | ) |
Get help information of entire parser.
- Returns
- All help information
Value zz::cfg::ArgParser::operator[] | ( | const std::string & | longKey | ) |
Overloaded operator [] to retrieve the value by long key.
- Parameters
-
longKey
- Returns
- Value type where the argument was stored
Value zz::cfg::ArgParser::operator[] | ( | const char | shortKey | ) |
Overloaded operator [] to retrieve the value by short key.
- Parameters
-
shortKey
- Returns
- Value type where the argument was stored
void zz::cfg::ArgParser::parse | ( | int | argc, |
char ** | argv, | ||
bool | ignoreUnknown = false |
||
) |
Start parsing arguments.
- Parameters
-
argc argv ignoreUnknown Whether or not ignore unknown option keys
|
inline |
Return version info.
- Returns
- Version info in string
The documentation for this class was generated from the following files:
- zupply.hpp
- zupply.cpp