A general purpose command-line argument parser.
More...
#include <ArgumentParser.h>
|
| | ArgumentParser (const std::string &title) |
| | Construct an argument parser. More...
|
| |
| void | parseArgs (int argc, const char **argv) |
| | Parses a list of strings given in the C style. Throws std::exception if parsing fails. More...
|
| |
| void | parse (const std::vector< std::string > &args) |
| | Parses a list of strings. Throws std::exception if parsing fails. More...
|
| |
| void | addOptionalIntArgument (const std::string &name, const std::string &description, int defaultValue) |
| | Specify an integer argument that can be given on the command line. More...
|
| |
| void | addOptionalFloatArgument (const std::string &name, const std::string &description, double defaultValue) |
| | Specify a floating-point argument that can be given on the command line. More...
|
| |
| void | addOptionalStringArgument (const std::string &name, const std::string &description, const std::string &defaultValue) |
| | Specify a string argument that can be given on the command line. More...
|
| |
| void | addOptionalFlag (const std::string &name, const std::string &description) |
| | Specify a boolean flag that can be given on the command line. More...
|
| |
| std::string | getUsage () const |
| | Gets a string that describes the current set of options we expect. More...
|
| |
| bool | receivedArgument (const std::string &name) const |
| | Gets whether a named argument was parsed on the command-line arguments. More...
|
| |
| int | getIntArgument (const std::string &name) const |
| | Retrieves the value of a named integer argument. More...
|
| |
| double | getFloatArgument (const std::string &name) const |
| | Retrieves the value of a named floating-point argument. More...
|
| |
| std::string | getStringArgument (const std::string &name) const |
| | Retrieves the value of a named string argument. More...
|
| |
A general purpose command-line argument parser.
◆ ArgumentParser()
| malmo::ArgumentParser::ArgumentParser |
( |
const std::string & |
title | ) |
|
Construct an argument parser.
- Parameters
-
| title | The title of the program to display. |
◆ addOptionalFlag()
| void malmo::ArgumentParser::addOptionalFlag |
( |
const std::string & |
name, |
|
|
const std::string & |
description |
|
) |
| |
Specify a boolean flag that can be given on the command line.
- Parameters
-
| name | The name of the flag. To be given as "--name" |
| description | The explanation of the flag that can be printed out. |
◆ addOptionalFloatArgument()
| void malmo::ArgumentParser::addOptionalFloatArgument |
( |
const std::string & |
name, |
|
|
const std::string & |
description, |
|
|
double |
defaultValue |
|
) |
| |
Specify a floating-point argument that can be given on the command line.
- Parameters
-
| name | The name of the argument. To be given as "--name <value>" |
| description | The explanation of the argument that can be printed out. |
| defaultValue | The value that this argument should have if not given on the command line. |
◆ addOptionalIntArgument()
| void malmo::ArgumentParser::addOptionalIntArgument |
( |
const std::string & |
name, |
|
|
const std::string & |
description, |
|
|
int |
defaultValue |
|
) |
| |
Specify an integer argument that can be given on the command line.
- Parameters
-
| name | The name of the argument. To be given as "--name <value>" |
| description | The explanation of the argument that can be printed out. |
| defaultValue | The value that this argument should have if not given on the command line. |
◆ addOptionalStringArgument()
| void malmo::ArgumentParser::addOptionalStringArgument |
( |
const std::string & |
name, |
|
|
const std::string & |
description, |
|
|
const std::string & |
defaultValue |
|
) |
| |
Specify a string argument that can be given on the command line.
- Parameters
-
| name | The name of the argument. To be given as "--name <value>" |
| description | The explanation of the argument that can be printed out. |
| defaultValue | The value that this argument should have if not given on the command line. |
◆ getFloatArgument()
| double malmo::ArgumentParser::getFloatArgument |
( |
const std::string & |
name | ) |
const |
Retrieves the value of a named floating-point argument.
- Parameters
-
| name | The name of the argument. |
- Returns
- The value of the named argument.
◆ getIntArgument()
| int malmo::ArgumentParser::getIntArgument |
( |
const std::string & |
name | ) |
const |
Retrieves the value of a named integer argument.
- Parameters
-
| name | The name of the argument. |
- Returns
- The value of the named argument.
◆ getStringArgument()
| std::string malmo::ArgumentParser::getStringArgument |
( |
const std::string & |
name | ) |
const |
Retrieves the value of a named string argument.
- Parameters
-
| name | The name of the argument. |
- Returns
- The value of the named argument.
◆ getUsage()
| std::string malmo::ArgumentParser::getUsage |
( |
| ) |
const |
Gets a string that describes the current set of options we expect.
- Returns
- The usage string, for displaying.
◆ parse()
| void malmo::ArgumentParser::parse |
( |
const std::vector< std::string > & |
args | ) |
|
Parses a list of strings. Throws std::exception if parsing fails.
In C++: takes a std::vector<std::string>. In Python: takes a list of strings. In Lua: takes a table of strings.
- Parameters
-
| args | The arguments to parse. |
◆ parseArgs()
| void malmo::ArgumentParser::parseArgs |
( |
int |
argc, |
|
|
const char ** |
argv |
|
) |
| |
Parses a list of strings given in the C style. Throws std::exception if parsing fails.
Available in C++ only. In other languages use the parse function instead.
- Parameters
-
| argc | The number of arguments. |
| argv | The arguments to parse. |
- See also
- parse()
◆ receivedArgument()
| bool malmo::ArgumentParser::receivedArgument |
( |
const std::string & |
name | ) |
const |
Gets whether a named argument was parsed on the command-line arguments.
- Parameters
-
| name | The name of the argument. |
- Returns
- True if the named argument was received.
The documentation for this class was generated from the following file: