CPP-AP 2.2.6
Command-line argument parser for C++20
|
Main argument parser class. More...
#include <argument_parser.hpp>
Public Member Functions | |
argument_parser (const argument_parser &)=delete | |
argument_parser & | operator= (const argument_parser &)=delete |
argument_parser (argument_parser &&)=default | |
argument_parser & | operator= (argument_parser &&)=default |
argument_parser & | program_name (std::string_view name) noexcept |
Set the program name. | |
argument_parser & | program_description (std::string_view description) noexcept |
Set the program description. | |
argument_parser & | verbose (const bool v=true) noexcept |
Set the verbosity mode. | |
template<detail::c_range_of< argument::default_positional > AR> | |
argument_parser & | default_positional_arguments (const AR &arg_discriminator_range) noexcept |
Set default positional arguments. | |
argument_parser & | default_positional_arguments (const std::initializer_list< argument::default_positional > arg_discriminator_list) noexcept |
Set default positional arguments. | |
template<detail::c_range_of< argument::default_optional > AR> | |
argument_parser & | default_optional_arguments (const AR &arg_discriminator_range) noexcept |
Set default optional arguments. | |
argument_parser & | default_optional_arguments (const std::initializer_list< argument::default_optional > arg_discriminator_list) noexcept |
Set default optional arguments. | |
template<detail::c_argument_value_type T = std::string> | |
argument::positional< T > & | add_positional_argument (std::string_view primary_name) |
Adds a positional argument to the parser's configuration. | |
template<detail::c_argument_value_type T = std::string> | |
argument::positional< T > & | add_positional_argument (std::string_view primary_name, std::string_view secondary_name) |
Adds a positional argument to the parser's configuration. | |
template<detail::c_argument_value_type T = std::string> | |
argument::optional< T > & | add_optional_argument (std::string_view primary_name) |
Adds a positional argument to the parser's configuration. | |
template<detail::c_argument_value_type T = std::string> | |
argument::optional< T > & | add_optional_argument (std::string_view primary_name, std::string_view secondary_name) |
Adds a positional argument to the parser's configuration. | |
template<bool StoreImplicitly = true> | |
argument::optional< bool > & | add_flag (std::string_view primary_name) |
Adds a boolean flag argument (an optional argument with value_type = bool ) to the parser's configuration. | |
template<bool StoreImplicitly = true> | |
argument::optional< bool > & | add_flag (std::string_view primary_name, std::string_view secondary_name) |
Adds a boolean flag argument (an optional argument with value_type = bool ) to the parser's configuration. | |
void | parse_args (int argc, char *argv[]) |
Parses the command-line arguments. | |
template<detail::c_range_of< std::string, detail::type_validator::convertible > AR> | |
void | parse_args (const AR &argv) |
Parses the command-line arguments. | |
void | try_parse_args (int argc, char *argv[]) |
Parses the command-line arguments and exits on error. | |
template<detail::c_range_of< std::string, detail::type_validator::convertible > AR> | |
void | try_parse_args (const AR &argv) |
Parses the command-line arguments and exits on error. | |
void | handle_help_action () const noexcept |
Handles the help argument logic. | |
bool | has_value (std::string_view arg_name) const noexcept |
std::size_t | count (std::string_view arg_name) const noexcept |
template<detail::c_argument_value_type T = std::string> | |
T | value (std::string_view arg_name) const |
template<detail::c_argument_value_type T = std::string, std::convertible_to< T > U> | |
T | value_or (std::string_view arg_name, U &&default_value) const |
template<detail::c_argument_value_type T = std::string> | |
std::vector< T > | values (std::string_view arg_name) const |
void | print_config (const bool verbose, std::ostream &os=std::cout) const noexcept |
Prints the argument parser's details to an output stream. | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const argument_parser &parser) noexcept |
Prints the argument parser's details to an output stream. | |
Main argument parser class.
Definition at line 45 of file argument_parser.hpp.
|
inline |
Adds a boolean flag argument (an optional argument with value_type = bool
) to the parser's configuration.
StoreImplicitly | A boolean value used as the implicit_value parameter of the argument. |
primary_name | The primary name of the flag. |
Definition at line 235 of file argument_parser.hpp.
|
inline |
Adds a boolean flag argument (an optional argument with value_type = bool
) to the parser's configuration.
StoreImplicitly | A boolean value used as the implicit_value parameter of the argument. |
primary_name | The primary name of the flag. |
secondary_name | The secondary name of the flag. |
Definition at line 250 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration.
T | Type of the argument value. |
primary_name | The primary name of the argument. |
ap::invalid_configuration |
Definition at line 192 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration.
T | Type of the argument value. |
primary_name | The primary name of the argument. |
secondary_name | The secondary name of the argument. |
ap::invalid_configuration |
Definition at line 214 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration.
T | Type of the argument value. |
primary_name | The primary name of the argument. |
ap::invalid_configuration |
Definition at line 146 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration.
T | Type of the argument value. |
primary_name | The primary name of the argument. |
secondary_name | The secondary name of the argument. |
ap::invalid_configuration |
Definition at line 168 of file argument_parser.hpp.
|
inlinenoexcept |
arg_name | The name of the argument. |
Definition at line 346 of file argument_parser.hpp.
|
inlinenoexcept |
Set default optional arguments.
AR | Type of the optional argument discriminator range. |
arg_discriminator_range | A range of default optional argument discriminators. |
Definition at line 119 of file argument_parser.hpp.
|
inlinenoexcept |
Set default optional arguments.
arg_discriminator_list | A list of default optional argument discriminators. |
Definition at line 130 of file argument_parser.hpp.
|
inlinenoexcept |
Set default positional arguments.
AR | Type of the positional argument discriminator range. |
arg_discriminator_range | A range of default positional argument discriminators. |
Definition at line 95 of file argument_parser.hpp.
|
inlinenoexcept |
Set default positional arguments.
arg_discriminator_list | A list of default positional argument discriminators. |
Definition at line 106 of file argument_parser.hpp.
|
inlinenoexcept |
Handles the help
argument logic.
Checks the value of the help
boolean flag argument and if the value is
true, prints the parser to std::cout
anb exists with EXIT_SUCCESS
status.
Definition at line 324 of file argument_parser.hpp.
|
inlinenoexcept |
arg_name | The name of the argument. |
Definition at line 337 of file argument_parser.hpp.
|
inline |
Parses the command-line arguments.
AR | The argument range type. |
argv | A range of command-line argument values. |
Definition at line 275 of file argument_parser.hpp.
|
inline |
Parses the command-line arguments.
argc | Number of command-line arguments. |
argv | Array of command-line argument values. |
Definition at line 265 of file argument_parser.hpp.
|
inlinenoexcept |
Prints the argument parser's details to an output stream.
verbose | The verbosity mode value. |
os | Output stream. |
Definition at line 438 of file argument_parser.hpp.
|
inlinenoexcept |
Set the program description.
description | The description of the program. |
Definition at line 72 of file argument_parser.hpp.
|
inlinenoexcept |
Set the program name.
name | The name of the program. |
Definition at line 62 of file argument_parser.hpp.
|
inline |
Parses the command-line arguments and exits on error.
Calls parse_args(argv)
in a try-catch block. If an error is thrown, then its message and the parser are printed to std::cerr
and the function exists with EXIT_FAILURE
status.
AR | The argument range type. |
argv | A range of command-line argument values. |
Definition at line 306 of file argument_parser.hpp.
|
inline |
Parses the command-line arguments and exits on error.
argc | Number of command-line arguments. |
argv | Array of command-line argument values. |
Definition at line 291 of file argument_parser.hpp.
|
inline |
T | Type of the argument value. |
arg_name | The name of the argument. |
ap::lookup_failure,ap::type_error |
Definition at line 358 of file argument_parser.hpp.
|
inline |
T | Type of the argument value. |
U | The default value type. |
arg_name | The name of the argument. |
default_value | The default value. |
ap::lookup_failure,ap::type_error |
Definition at line 381 of file argument_parser.hpp.
|
inline |
T | Type of the argument values. |
arg_name | The name of the argument. |
ap::lookup_failure,ap::type_error |
Definition at line 407 of file argument_parser.hpp.
|
inlinenoexcept |
Set the verbosity mode.
false
. v | The verbosity mode value. |
Definition at line 83 of file argument_parser.hpp.
|
friend |
Prints the argument parser's details to an output stream.
An os << parser
operation is equivalent to a parser.print_config(_verbose, os)
call, where _verbose
is the inner verbosity mode, which can be set with the verbose function.
os | Output stream. |
parser | The argument parser to print. |
Definition at line 468 of file argument_parser.hpp.