The parser class provides the argument parser for the CLI and JSON methods. This is case insensitive.
More...
#include <BSMPT/utility/parser.h>
|
| parser (const bool &enable_column_output) |
|
void | enable_minimizer_options () |
| enable_minimizer_options Enables the options regarding the minimizer.
|
|
void | add_argument_only_display (const std::string &argument, const std::string &description, const std::string &default_val) |
| add_argument Silently adds a new argument for the parser options.
|
|
void | add_argument (const std::string &argument, bool required) |
| add_argument Silently adds a new argument for the parser options.
|
|
void | add_argument (const std::string &argument, const std::string &description, bool required) |
| add_argument Adds a new argument for the parser options.
|
|
void | add_argument (const std::string &argument, const std::string &description, const std::string &default_val, bool required) |
| add_argument Adds a new argument for the parser options.
|
|
void | add_subtext (const std::string &subtext) |
| add_subtext add subtext to description column
|
|
void | add_input (const std::vector< std::string > &input) |
| add_input Add the vector with each input as it is given in the CLI in the form "--argument=value".
|
|
void | print_help () const |
| print_help Prints the header and the arguments with their description.
|
|
template<typename T = std::string> |
T | get_value (const std::string &argument) const |
| get_value Get the value for the required parameter.
|
|
bool | all_required_set () const |
| all_required_set Check ifs all required parameter are set.
|
|
void | check_required_parameters () const |
| check_required_parameters Calls all_required_set() and throws a parserException if not all required parameters are set.
|
|
void | set_help_header (const std::string &header) |
| set_help_header Sets the header which is printed in print_help()
|
|
|
std::string | get_value_as_string (const std::string &argument) const |
| get_value Get the value for the required parameter.
|
|
void | add_json_input (const std::string &filename) |
| add_json_input Add the input parameters with a json file.
|
|
void | add_input (const std::vector< KeyValue > &input) |
| add_input Set the key value pairs.
|
|
std::string | to_lower (const std::string &input) const |
| get_key_value Converts the CLI input in the form "--argName=value" into a key value pair.
|
|
KeyValue | get_key_value (const std::string &input) |
|
|
std::vector< std::pair< std::string, Options > > | mOrderedArguments |
|
std::unordered_map< std::string, Options > | mRequiredArguments |
|
std::unordered_map< std::string, Options > | mOptionalArguments |
|
bool | extra_column_output = false |
|
std::string | mHeader |
|
bool | mHelpAlreadyPrinted {false} |
| Helper to avoid multiple prints of the help output.
|
|
The parser class provides the argument parser for the CLI and JSON methods. This is case insensitive.
◆ add_argument() [1/3]
void BSMPT::parser::add_argument |
( |
const std::string & |
argument, |
|
|
bool |
required |
|
) |
| |
add_argument Silently adds a new argument for the parser options.
- Parameters
-
argument | The parameter name for the CLI or JSON key. This will be treated case insensitive. |
required | Decide if it is a required parameter or not. |
◆ add_argument() [2/3]
void BSMPT::parser::add_argument |
( |
const std::string & |
argument, |
|
|
const std::string & |
description, |
|
|
bool |
required |
|
) |
| |
add_argument Adds a new argument for the parser options.
- Parameters
-
argument | The parameter name for the CLI or JSON key. This will be treated case insensitive. |
description | The description for the parameter shown in help. |
required | Decide if it is a required parameter or not. |
◆ add_argument() [3/3]
void BSMPT::parser::add_argument |
( |
const std::string & |
argument, |
|
|
const std::string & |
description, |
|
|
const std::string & |
default_val, |
|
|
bool |
required |
|
) |
| |
add_argument Adds a new argument for the parser options.
- Parameters
-
argument | The parameter name for the CLI or JSON key. This will be treated case insensitive. |
description | The description for the parameter shown in help. |
default_val | The default value for optional parameters. |
required | Decide if it is a required parameter or not. |
◆ add_argument_only_display()
void BSMPT::parser::add_argument_only_display |
( |
const std::string & |
argument, |
|
|
const std::string & |
description, |
|
|
const std::string & |
default_val |
|
) |
| |
add_argument Silently adds a new argument for the parser options.
- Parameters
-
argument | The parameter name for the CLI or JSON key. This will be treated case insensitive. |
description | The description for the parameter shown in help. |
default_val | The default value for optional parameters. |
◆ add_input() [1/2]
void BSMPT::parser::add_input |
( |
const std::vector< KeyValue > & |
input | ) |
|
|
private |
add_input Set the key value pairs.
- Parameters
-
input | The vector containing all key value pairs. |
◆ add_input() [2/2]
void BSMPT::parser::add_input |
( |
const std::vector< std::string > & |
input | ) |
|
add_input Add the vector with each input as it is given in the CLI in the form "--argument=value".
- Parameters
-
input | The vector containing the CLI inputs. |
- Exceptions
-
◆ add_json_input()
void BSMPT::parser::add_json_input |
( |
const std::string & |
filename | ) |
|
|
private |
add_json_input Add the input parameters with a json file.
- Parameters
-
filename | The file containing the json. |
◆ add_subtext()
void BSMPT::parser::add_subtext |
( |
const std::string & |
subtext | ) |
|
add_subtext add subtext to description column
- Parameters
-
subtext | string to print in description column |
◆ all_required_set()
bool BSMPT::parser::all_required_set |
( |
| ) |
const |
all_required_set Check ifs all required parameter are set.
- Returns
- true/false if all required parameters are set.
◆ check_required_parameters()
void BSMPT::parser::check_required_parameters |
( |
| ) |
const |
◆ get_value()
template<typename T = std::string>
T BSMPT::parser::get_value |
( |
const std::string & |
argument | ) |
const |
|
inline |
get_value Get the value for the required parameter.
- Parameters
-
argument | The required CLI name or JSON key. |
- Returns
- The value if the parameter was set.
- Exceptions
-
parserException | if the argument was not set or if the value can not be casted from a string to the type. |
◆ get_value_as_string()
std::string BSMPT::parser::get_value_as_string |
( |
const std::string & |
argument | ) |
const |
|
private |
get_value Get the value for the required parameter.
- Parameters
-
argument | The required CLI name or JSON key. |
- Returns
- The value if the parameter was set.
- Exceptions
-
parserException | if the argument was not set or if the value can not be casted from a string to the type. |
◆ set_help_header()
void BSMPT::parser::set_help_header |
( |
const std::string & |
header | ) |
|
set_help_header Sets the header which is printed in print_help()
- Parameters
-
header | The header to print. |
◆ to_lower()
std::string BSMPT::parser::to_lower |
( |
const std::string & |
input | ) |
const |
|
private |
get_key_value Converts the CLI input in the form "--argName=value" into a key value pair.
- Parameters
-
input | The CLI option in the form of "--argName=foo". |
- Returns
- Returns the matching KeyValue.
The documentation for this class was generated from the following files:
- include/BSMPT/utility/parser.h
- src/utility/parser.cpp