Represents the context of a command-line interface (CLI) invocation and as such contains the parsed values (if present for all Arguments)
More...
#include <cli_context.h>
|
| | CliContext (std::unique_ptr< std::unordered_map< std::string, std::any > > posArgs, std::unique_ptr< std::unordered_map< std::string, std::any > > optArgs, std::unique_ptr< std::unordered_set< std::string > > flagArgs, cli::logging::AbstractLogger &logger) |
| | Constructs a new CliContext object from the passed argument maps.
|
| |
|
| CliContext (const CliContext &)=delete |
| |
|
CliContext & | operator= (const CliContext &)=delete |
| |
| bool | isArgPresent (const std::string &argName) const |
| | Checks if an argument with the given name is present in the context.
|
| |
| bool | isOptionArgPresent (const std::string &argName) const |
| | Checks if an optional argument with the given name is present in the context.
|
| |
| bool | isPositionalArgPresent (const std::string &argName) const |
| | Checks if a positional argument with the given name is present in the context.
|
| |
| bool | isFlagPresent (const std::string &argName) const |
| | Checks if a flag with the given name is present in the context.
|
| |
| template<typename T > |
| T | getPositionalArg (const std::string &argName) const |
| | Gets the value of a positional argument.
|
| |
| template<typename T > |
| void | getPositionalArg (const std::string &argName, T &out) const |
| | Gets the value of a positional argument and stores it in the provided output variable.
|
| |
| template<typename T > |
| T | getOptionArg (const std::string &argName) const |
| | Gets the value of an optional argument.
|
| |
| template<typename T > |
| void | getOptionArg (const std::string &argName, T &out) const |
| | Gets the value of an optional argument and stores it in the provided output variable.
|
| |
| template<typename T > |
| std::vector< T > | getRepeatableOptionArg (const std::string &argName) const |
| | Gets all values of a repeatable option argument.
|
| |
| template<typename T > |
| std::vector< T > | getRepeatablePositionalArg (const std::string &argName) const |
| | Gets all values of a repeatable positional argument.
|
| |
| template<typename T > |
| T | getArg (const std::string &argName) const |
| | Gets the value of an argument.
|
| |
| template<typename T > |
| auto | getRepeatableArg (const std::string &argName) const |
| | Gets all values of a repeatable argument.
|
| |
|
logging::AbstractLogger & | Logger () const |
| |
Represents the context of a command-line interface (CLI) invocation and as such contains the parsed values (if present for all Arguments)
◆ CliContext()
| cli::CliContext::CliContext |
( |
std::unique_ptr< std::unordered_map< std::string, std::any > > |
posArgs, |
|
|
std::unique_ptr< std::unordered_map< std::string, std::any > > |
optArgs, |
|
|
std::unique_ptr< std::unordered_set< std::string > > |
flagArgs, |
|
|
cli::logging::AbstractLogger & |
logger |
|
) |
| |
|
inlineexplicit |
Constructs a new CliContext object from the passed argument maps.
- Parameters
-
| posArgs | a map of positional argument names to their values |
| optArgs | a map of optional argument names to their values |
| flagArgs | a set of flag argument names |
| logger | a logger instance to use in the methods this object is passed to |
◆ getArg()
template<typename T >
| T cli::CliContext::getArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets the value of an argument.
- Template Parameters
-
| T | the type to cast the argument value to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the argument to retrieve |
- Returns
- the value of the argument cast to the specified type
◆ getOptionArg() [1/2]
template<typename T >
| T cli::CliContext::getOptionArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets the value of an optional argument.
- Template Parameters
-
| T | the type to cast the argument value to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the optional argument to retrieve |
- Returns
- the value of the optional argument cast to the specified type
◆ getOptionArg() [2/2]
template<typename T >
| void cli::CliContext::getOptionArg |
( |
const std::string & |
argName, |
|
|
T & |
out |
|
) |
| const |
|
inline |
Gets the value of an optional argument and stores it in the provided output variable.
- Template Parameters
-
| T | the type to cast the argument value to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the optional argument to retrieve |
| out | the output variable to store the argument value in |
◆ getPositionalArg() [1/2]
template<typename T >
| T cli::CliContext::getPositionalArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets the value of a positional argument.
- Template Parameters
-
| T | the type to cast the argument value to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the positional argument to retrieve |
- Returns
- the value of the positional argument cast to the specified type
◆ getPositionalArg() [2/2]
template<typename T >
| void cli::CliContext::getPositionalArg |
( |
const std::string & |
argName, |
|
|
T & |
out |
|
) |
| const |
|
inline |
Gets the value of a positional argument and stores it in the provided output variable.
- Template Parameters
-
| T | the type to cast the argument value to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the positional argument to retrieve |
| out | the output variable to store the argument value in |
◆ getRepeatableArg()
template<typename T >
| auto cli::CliContext::getRepeatableArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets all values of a repeatable argument.
- Template Parameters
-
| T | the type to cast the argument values to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the repeatable argument to retrieve |
- Returns
- a vector of all values of the repeatable argument cast to the specified type
◆ getRepeatableOptionArg()
template<typename T >
| std::vector< T > cli::CliContext::getRepeatableOptionArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets all values of a repeatable option argument.
- Template Parameters
-
| T | the type to cast the single argument values to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the repeatable option argument to retrieve |
- Returns
- a vector of all values of the repeatable option argument cast to the specified type
◆ getRepeatablePositionalArg()
template<typename T >
| std::vector< T > cli::CliContext::getRepeatablePositionalArg |
( |
const std::string & |
argName | ) |
const |
|
inline |
Gets all values of a repeatable positional argument.
- Template Parameters
-
| T | the type to cast the single argument values to (should be the same as the one used in defining the Argument) |
- Parameters
-
| argName | the name of the repeatable positional argument to retrieve |
- Returns
- a vector of all values of the repeatable positional argument cast to the specified type
◆ isArgPresent()
| inline_t bool cli::CliContext::isArgPresent |
( |
const std::string & |
argName | ) |
const |
Checks if an argument with the given name is present in the context.
- Parameters
-
| argName | the name of the argument to check |
- Returns
- true if the argument is present, false otherwise
◆ isFlagPresent()
| inline_t bool cli::CliContext::isFlagPresent |
( |
const std::string & |
argName | ) |
const |
Checks if a flag with the given name is present in the context.
- Parameters
-
| argName | the name of the argument to check |
- Returns
- true if the argument is present, false otherwise
◆ isOptionArgPresent()
| inline_t bool cli::CliContext::isOptionArgPresent |
( |
const std::string & |
argName | ) |
const |
Checks if an optional argument with the given name is present in the context.
- Parameters
-
| argName | the name of the argument to check |
- Returns
- true if the argument is present, false otherwise
◆ isPositionalArgPresent()
| inline_t bool cli::CliContext::isPositionalArgPresent |
( |
const std::string & |
argName | ) |
const |
Checks if a positional argument with the given name is present in the context.
- Parameters
-
| argName | the name of the argument to check |
- Returns
- true if the argument is present, false otherwise
The documentation for this class was generated from the following files: