|
CPP-AP 3.0.1
Command-line argument parser for C++20
|
The main argument parser class. More...
#include <argument_parser.hpp>
Classes | |
| struct | parsing_state |
| A collection of values used during the parsing process. More... | |
Public Member Functions | |
| argument_parser (const argument_parser &)=delete | |
| argument_parser & | operator= (const argument_parser &)=delete |
| argument_parser (argument_parser &&)=delete | |
| argument_parser & | operator= (argument_parser &&)=delete |
| argument_parser (const std::string_view name) | |
| ~argument_parser ()=default | |
| argument_parser & | program_version (const version &version) noexcept |
| Set the program version. | |
| argument_parser & | program_version (std::string_view version) |
| Set the program version. | |
| 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. | |
| argument_parser & | unknown_arguments_policy (const unknown_policy policy) noexcept |
| Set the unknown argument flags handling policy. | |
| template<util::c_range_of< default_argument > AR> | |
| argument_parser & | default_arguments (const AR &arg_discriminators) noexcept |
| Add default arguments to the argument parser. | |
| argument_parser & | default_arguments (const std::initializer_list< default_argument > &arg_discriminators) noexcept |
| Add default arguments to the argument parser. | |
| argument_parser & | default_arguments (const std::same_as< default_argument > auto... arg_discriminators) noexcept |
| Add default arguments to the argument parser. | |
| template<util::c_argument_value_type T = std::string> | |
| positional_argument< T > & | add_positional_argument (const std::string_view name) |
| Adds a positional argument to the parser's configuration. | |
| template<util::c_argument_value_type T = std::string> | |
| positional_argument< T > & | add_positional_argument (argument_group &group, const std::string_view name) |
| Adds a positional argument to the parser's configuration and binds it to the given group. | |
| template<util::c_argument_value_type T = std::string> | |
| optional_argument< T > & | add_optional_argument (const std::string_view name, const detail::argument_name_discriminator name_discr=n_primary) |
| Adds an optional argument to the parser's configuration. | |
| template<util::c_argument_value_type T = std::string> | |
| optional_argument< T > & | add_optional_argument (const std::string_view primary_name, const std::string_view secondary_name) |
| Adds an optional argument to the parser's configuration. | |
| template<util::c_argument_value_type T = std::string> | |
| optional_argument< T > & | add_optional_argument (argument_group &group, const std::string_view name, const detail::argument_name_discriminator name_discr=n_primary) |
| Adds an optional argument to the parser's configuration and binds it to the given group. | |
| template<util::c_argument_value_type T = std::string> | |
| optional_argument< T > & | add_optional_argument (argument_group &group, const std::string_view primary_name, const std::string_view secondary_name) |
| Adds an optional argument to the parser's configuration and binds it to the given group. | |
| template<bool StoreImplicitly = true> | |
| optional_argument< bool > & | add_flag (const std::string_view name, const detail::argument_name_discriminator name_discr=n_primary) |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration. | |
| template<bool StoreImplicitly = true> | |
| optional_argument< bool > & | add_flag (const std::string_view primary_name, const std::string_view secondary_name) |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration. | |
| template<bool StoreImplicitly = true> | |
| optional_argument< bool > & | add_flag (argument_group &group, const std::string_view name, const detail::argument_name_discriminator name_discr=n_primary) |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration and binds it to the given group. | |
| template<bool StoreImplicitly = true> | |
| optional_argument< bool > & | add_flag (argument_group &group, const std::string_view primary_name, const std::string_view secondary_name) |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration and binds it to the given group. | |
| argument_group & | add_group (const std::string_view name) noexcept |
| Adds an argument group with the given name to the parser's configuration. | |
| argument_parser & | add_subparser (const std::string_view name) |
| Adds an subparser with the given name to the parser's configuration. | |
| void | parse_args (int argc, char *argv[]) |
| Parses the command-line arguments. | |
| template<util::c_forward_range_of< std::string, util::type_validator::convertible > AR> | |
| void | parse_args (const AR &argv_rng) |
| Parses the command-line arguments. | |
| void | try_parse_args (int argc, char *argv[]) |
| Parses the command-line arguments and exits on error. | |
| template<util::c_forward_range_of< std::string, util::type_validator::convertible > AR> | |
| void | try_parse_args (const AR &argv_rng) |
| Parses the command-line arguments and exits on error. | |
| std::vector< std::string > | parse_known_args (int argc, char *argv[]) |
| Parses the known command-line arguments. | |
| template<util::c_forward_range_of< std::string, util::type_validator::convertible > AR> | |
| std::vector< std::string > | parse_known_args (const AR &argv_rng) |
| Parses the known command-line arguments. | |
| std::vector< std::string > | try_parse_known_args (int argc, char *argv[]) |
| Parses the known command-line arguments and exits on error. | |
| template<util::c_forward_range_of< std::string, util::type_validator::convertible > AR> | |
| std::vector< std::string > | try_parse_known_args (const AR &argv_rng) |
| Parses known the command-line arguments and exits on error. | |
| std::string_view | name () const noexcept |
| Returns the parser's name. | |
| std::string_view | program_name () const noexcept |
| bool | invoked () const noexcept |
| Check whether this parser was invoked. | |
| bool | finalized () const noexcept |
| Check whether the parser has finalized parsing its own arguments. | |
| argument_parser & | resolved_parser () noexcept |
| Returns the deepest invoked parser. | |
| bool | is_used (std::string_view arg_name) const noexcept |
| Check if a specific argument was used in the command-line. | |
| bool | has_value (std::string_view arg_name) const noexcept |
| Check if the given argument has a value. | |
| std::size_t | count (std::string_view arg_name) const noexcept |
| Get the given argument's usage count. | |
| template<util::c_argument_value_type T = std::string> | |
| T | value (std::string_view arg_name) const |
| Get the value of the given argument. | |
| template<util::c_argument_value_type T = std::string, std::convertible_to< T > U> | |
| T | value_or (std::string_view arg_name, U &&fallback_value) const |
| Get the value of the given argument, if it has any, or a fallback value, if not. | |
| template<util::c_argument_value_type T = std::string> | |
| std::vector< T > | values (std::string_view arg_name) const |
| Get all values of the given argument. | |
| void | print_help (const bool verbose, std::ostream &os=std::cout) const noexcept |
| Prints the argument parser's help message to an output stream. | |
| void | print_version (std::ostream &os=std::cout) const noexcept |
| Prints the argument parser's version info to an output stream. | |
Private Types | |
| using | arg_ptr_t = std::shared_ptr< detail::argument_base > |
| using | arg_ptr_vec_t = std::vector< arg_ptr_t > |
| using | arg_ptr_vec_iter_t = typename arg_ptr_vec_t::iterator |
| using | arg_group_ptr_t = std::unique_ptr< argument_group > |
| using | arg_group_ptr_vec_t = std::vector< arg_group_ptr_t > |
| using | arg_parser_ptr_t = std::unique_ptr< argument_parser > |
| using | arg_parser_ptr_vec_t = std::vector< arg_parser_ptr_t > |
| using | arg_token_vec_t = std::vector< detail::argument_token > |
| using | arg_token_vec_iter_t = typename arg_token_vec_t::const_iterator |
Private Member Functions | |
| argument_parser (const std::string_view name, const std::string_view parent_name) | |
| void | _verify_arg_name_pattern (const std::string_view arg_name) const |
| Verifies the pattern of an argument name and if it's invalid, an error is thrown. | |
| auto | _name_match_predicate (const std::string_view arg_name, const detail::argument_name::match_type m_type=detail::argument_name::m_any) const noexcept |
| Returns a unary predicate function which checks if the given name matches the argument's name. | |
| auto | _name_match_predicate (const detail::argument_name &arg_name, const detail::argument_name::match_type m_type=detail::argument_name::m_any) const noexcept |
| Returns a unary predicate function which checks if the given name matches the argument's name. | |
| bool | _is_arg_name_used (const detail::argument_name &arg_name, const detail::argument_name::match_type m_type=detail::argument_name::m_any) const noexcept |
| Check if an argument name is already used. | |
| void | _validate_group (const argument_group &group) |
| Check if the given group belongs to the parser. | |
| template<util::c_forward_iterator_of< std::string, util::type_validator::convertible > AIt> | |
| void | _parse_args_impl (AIt args_begin, const AIt args_end, parsing_state &state) |
| Implementation of parsing command-line arguments. | |
| void | _validate_argument_configuration () const |
| Validate whether the definition/configuration of the parser's arguments is correct. | |
| template<util::c_forward_iterator_of< std::string, util::type_validator::convertible > AIt> | |
| arg_token_vec_t | _tokenize (AIt args_begin, const AIt args_end, const parsing_state &state) |
| Converts the command-line arguments into a list of tokens. | |
| void | _tokenize_arg (const std::string_view arg_value, arg_token_vec_t &toks, const parsing_state &state) |
Appends an argument token(s) created from arg_value to the toks vector. | |
| detail::argument_token::token_type | _deduce_token_type (const std::string_view arg_value) const noexcept |
| Returns the most appropriate initial token type based on a command-line argument's value. | |
| bool | _validate_flag_token (detail::argument_token &tok) noexcept |
| Check if a flag token is valid based on its value. | |
| bool | _validate_compound_flag_token (detail::argument_token &tok) noexcept |
| Check if a flag token is a valid compound argument flag based on its value. | |
| arg_ptr_vec_iter_t | _find_opt_arg (const detail::argument_token &flag_tok) noexcept |
| Find an optional argument based on a flag token. | |
| std::string_view | _strip_flag_prefix (const detail::argument_token &tok) const noexcept |
| Removes the flag prefix from a flag token's value. | |
| void | _parse_token (const detail::argument_token &tok, parsing_state &state) |
| Parse a single command-line argument token. | |
| void | _parse_flag_token (const detail::argument_token &tok, parsing_state &state) |
| Parse a single command-line argument flag token. | |
| void | _parse_value_token (const detail::argument_token &tok, parsing_state &state) |
| Parse a single command-line argument value token. | |
| void | _set_argument_value (const std::string_view value, parsing_state &state) noexcept |
| Set the value for the currently processed argument. | |
| void | _verify_final_state () const |
| Verifies the correctness of the parsed command-line arguments. | |
| std::pair< bool, bool > | _are_checks_suppressed () const noexcept |
| Check whether required argument group checks or argument checks suppressing is enabled. | |
| void | _verify_group_requirements (const argument_group &group, const bool suppress_group_checks, const bool suppress_arg_checks) const |
| Verifies whether the requirements of the given argument group are satisfied. | |
| void | _verify_argument_requirements (const arg_ptr_t &arg, const bool suppress_arg_checks) const |
| Verifies whether the requirements of the given argument are satisfied. | |
| arg_ptr_t | _get_argument (std::string_view arg_name) const noexcept |
| Get the argument with the specified name. | |
| void | _print_subparsers (std::ostream &os) const noexcept |
| void | _print_group (std::ostream &os, const argument_group &group, const bool verbose) const noexcept |
| Print the given argument list to an output stream. | |
Private Attributes | |
| std::string | _name |
| The name of the parser. | |
| std::string | _program_name |
| The name of the program in the format "<parent-parser-names>... <program-name>". | |
| std::optional< std::string > | _program_version |
| The version of the program. | |
| std::optional< std::string > | _program_description |
| The description of the program. | |
| bool | _verbose = false |
| Verbosity flag. | |
| unknown_policy | _unknown_policy = unknown_policy::fail |
| Policy for unknown arguments. | |
| arg_ptr_vec_t | _positional_args |
| The list of positional arguments. | |
| arg_ptr_vec_t | _optional_args |
| The list of optional arguments. | |
| arg_group_ptr_vec_t | _argument_groups |
| The list of argument groups. | |
| argument_group & | _gr_positional_args |
| The positional argument group. | |
| argument_group & | _gr_optional_args |
| The optional argument group. | |
| arg_parser_ptr_vec_t | _subparsers |
| The list of subparsers. | |
| bool | _invoked |
| A flag indicating whether the parser has been invoked to parse arguments. | |
| bool | _finalized = false |
| A flag indicating whether the parsing process has been finalized. | |
Static Private Attributes | |
| static constexpr std::uint8_t | _primary_flag_prefix_length = 2u |
| static constexpr std::uint8_t | _secondary_flag_prefix_length = 1u |
| static constexpr char | _flag_prefix_char = '-' |
| static constexpr std::string_view | _flag_prefix = "--" |
| static constexpr std::uint8_t | _indent_width = 2 |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const argument_parser &parser) noexcept |
| Prints the argument parser's details to an output stream. | |
The main argument parser class.
This class provides methods to define positional and optional arguments, set parser options, and parse the command-line input.
Example usage:
Definition at line 179 of file argument_parser.hpp.
|
private |
Definition at line 906 of file argument_parser.hpp.
|
private |
Definition at line 907 of file argument_parser.hpp.
|
private |
Definition at line 909 of file argument_parser.hpp.
|
private |
Definition at line 910 of file argument_parser.hpp.
|
private |
Definition at line 902 of file argument_parser.hpp.
|
private |
Definition at line 904 of file argument_parser.hpp.
|
private |
Definition at line 903 of file argument_parser.hpp.
|
private |
Definition at line 913 of file argument_parser.hpp.
|
private |
Definition at line 912 of file argument_parser.hpp.
|
delete |
|
delete |
|
inline |
Definition at line 187 of file argument_parser.hpp.
|
default |
|
inlineprivate |
Definition at line 937 of file argument_parser.hpp.
Check whether required argument group checks or argument checks suppressing is enabled.
Definition at line 1374 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Returns the most appropriate initial token type based on a command-line argument's value.
The token's initial type is deduced using the following rules:
t_value: an argument contains whitespace characters or cannot be a flag tokent_flag_primary: an argument begins with a primary flag prefix (--)t_flag_secondary: an argument begins with a secondary flag prefix (-)t_flag_compound: INITIALLY a token can NEVER have a compound flag type (may only be set when a flag token is validated) Definition at line 1173 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Find an optional argument based on a flag token.
| flag_tok | An argument_token instance, the value of which will be used to find the argument. |
flag_tok.type is not a valid flag token, then the end iterator will be returned. Definition at line 1243 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Get the argument with the specified name.
| arg_name | The name of the argument. |
Definition at line 1464 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Check if an argument name is already used.
| arg_name | The name of the argument. |
| m_type | The match type used to find the argument. |
Definition at line 1015 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Returns a unary predicate function which checks if the given name matches the argument's name.
| arg_name | The name of the argument. |
| m_type | The match type used within the predicate. |
Definition at line 1000 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Returns a unary predicate function which checks if the given name matches the argument's name.
| arg_name | The name of the argument. |
| m_type | The match type used within the predicate. |
Definition at line 987 of file argument_parser.hpp.
|
inlineprivate |
Implementation of parsing command-line arguments.
| AIt | The command-line argument value iterator type. |
AIt must be a std::forward_iterator with a value type convertible to std::string. | args_begin | The begin iterator for the command-line argument value range. |
| args_end | The end iterator for the command-line argument value range. |
| state | The current parsing state. |
| ap::invalid_configuration,ap::parsing_failure |
Definition at line 1052 of file argument_parser.hpp.
|
inlineprivate |
Parse a single command-line argument flag token.
| tok | The token to be parsed. |
| state | The current parsing state. |
| ap::parsing_failure |
Definition at line 1300 of file argument_parser.hpp.
|
inlineprivate |
Parse a single command-line argument token.
| tok | The token to be parsed. |
| state | The current parsing state. |
| ap::parsing_failure |
Definition at line 1282 of file argument_parser.hpp.
|
inlineprivate |
Parse a single command-line argument value token.
| tok | The token to be parsed. |
| state | The current parsing state. |
| ap::parsing_failure |
Definition at line 1327 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Print the given argument list to an output stream.
| os | The output stream to print to. |
| group | The argument group to print. |
| verbose | A verbosity mode indicator flag. |
Definition at line 1509 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Definition at line 1480 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Set the value for the currently processed argument.
state.curr_arg != nullptr). | value | The value to be set for the current argument. |
| state | The current parsing state. |
Definition at line 1346 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Removes the flag prefix from a flag token's value.
| tok | The argument token to be processed. |
Definition at line 1264 of file argument_parser.hpp.
|
inlineprivate |
Converts the command-line arguments into a list of tokens.
| AIt | The command-line argument value iterator type. |
AIt must be a std::forward_iterator with a value type convertible to std::string. | args_begin | The begin iterator for the command-line argument value range. |
| args_end | The end iterator for the command-line argument value range. |
| state | The current parsing state. |
Definition at line 1112 of file argument_parser.hpp.
|
inlineprivate |
Appends an argument token(s) created from arg_value to the toks vector.
| arg_value | The command-line argument's value to be processed. |
| toks | The argument token list to which the processed token(s) will be appended. |
| state | The current parsing state. |
Definition at line 1129 of file argument_parser.hpp.
|
inlineprivate |
Validate whether the definition/configuration of the parser's arguments is correct.
What is verified:
Definition at line 1083 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Check if a flag token is a valid compound argument flag based on its value.
t_flag_compuund args list is filled with all the arguments the token represents. | tok | The argument token to validate. |
true if the given token represents a valid compound argument flag. Definition at line 1210 of file argument_parser.hpp.
|
inlineprivatenoexcept |
Check if a flag token is valid based on its value.
args member of the token if an argument with the given name (token's value) is present. | tok | The argument token to validate. |
true if the given token represents a valid argument flag. Definition at line 1194 of file argument_parser.hpp.
|
inlineprivate |
Check if the given group belongs to the parser.
| group | The group to validate. |
| std::logic_error | if the group doesn't belong to the parser. |
Definition at line 1035 of file argument_parser.hpp.
|
inlineprivate |
Verifies the pattern of an argument name and if it's invalid, an error is thrown.
| ap::invalid_configuration |
Definition at line 955 of file argument_parser.hpp.
|
inlineprivate |
Verifies whether the requirements of the given argument are satisfied.
| arg | The argument to verify. |
| suppress_arg_checks | A flag indicating whether argument checks are suppressed. |
| ap::parsing_failure | if the requirements are not satistied. |
Definition at line 1447 of file argument_parser.hpp.
|
inlineprivate |
Verifies the correctness of the parsed command-line arguments.
| ap::parsing_failure | if the state of the parsed arguments is invalid. |
Definition at line 1362 of file argument_parser.hpp.
|
inlineprivate |
Verifies whether the requirements of the given argument group are satisfied.
| group | The argument group to verify. |
| suppress_arg_checks | A flag indicating whether argument checks are suppressed. |
| ap::parsing_failure | if the requirements are not satistied. |
Definition at line 1399 of file argument_parser.hpp.
|
inline |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration and binds it to the given group.
| StoreImplicitly | A boolean value used as the implicit_values parameter of the argument. |
default_values attribute will be set to not StoreImplicitly. | group | The argument group to bind the new argument to. |
| name | The primary name of the flag. |
| name_discr | The discriminator value specifying whether the given name should be treated as primary or secondary. |
Definition at line 468 of file argument_parser.hpp.
|
inline |
Adds a boolean flag argument (an optional argument with value_type = bool) to the parser's configuration and binds it to the given group.
| StoreImplicitly | A boolean value used as the implicit_values parameter of the argument. |
default_values attribute will be set to not StoreImplicitly. | group | The argument group to bind the new argument to. |
| primary_name | The primary name of the flag. |
| secondary_name | The secondary name of the flag. |
Definition at line 489 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_values parameter of the argument. |
default_values attribute will be set to not StoreImplicitly. | name | The primary name of the flag. |
| name_discr | The discriminator value specifying whether the given name should be treated as primary or secondary. |
Definition at line 430 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_values parameter of the argument. |
default_values attribute will be set to not StoreImplicitly. | primary_name | The primary name of the flag. |
| secondary_name | The secondary name of the flag. |
Definition at line 449 of file argument_parser.hpp.
|
inlinenoexcept |
Adds an argument group with the given name to the parser's configuration.
| name | Name of the group. |
Definition at line 505 of file argument_parser.hpp.
|
inline |
Adds an optional argument to the parser's configuration and binds it to the given group.
| T | Type of the argument value. |
| group | The argument group to bind the new argument to. |
| name | The name of the argument. |
| name_discr | The discriminator value specifying whether the given name should be treated as primary or secondary. |
| std::logic_error,ap::invalid_configuration |
Definition at line 363 of file argument_parser.hpp.
|
inline |
Adds an optional argument to the parser's configuration and binds it to the given group.
| T | Type of the argument value. |
| group | The argument group to bind the new argument to. |
| primary_name | The primary name of the argument. |
| secondary_name | The secondary name of the argument. |
| ap::invalid_configuration |
Definition at line 398 of file argument_parser.hpp.
|
inline |
Adds an optional argument to the parser's configuration.
| T | Type of the argument value. |
| name | The name of the argument. |
| name_discr | The discriminator value specifying whether the given name should be treated as primary or secondary. |
| ap::invalid_configuration |
Definition at line 329 of file argument_parser.hpp.
|
inline |
Adds an optional 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 345 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration and binds it to the given group.
| T | Type of the argument value. |
| primary_name | The name of the argument. |
| ap::invalid_configuration |
Definition at line 304 of file argument_parser.hpp.
|
inline |
Adds a positional argument to the parser's configuration.
| T | Type of the argument value. |
| name | The name of the argument. |
| ap::invalid_configuration |
Definition at line 292 of file argument_parser.hpp.
|
inline |
Adds an subparser with the given name to the parser's configuration.
| name | Name of the subparser. |
Definition at line 514 of file argument_parser.hpp.
|
inlinenoexcept |
Get the given argument's usage count.
| arg_name | The name of the argument. |
Definition at line 766 of file argument_parser.hpp.
|
inlinenoexcept |
Add default arguments to the argument parser.
| AR | Type of the positional argument discriminator range. |
| arg_discriminators | A range of default positional argument discriminators. |
arg_discriminators must be a std::ranges::range with the ap::default_argument value type. Definition at line 255 of file argument_parser.hpp.
|
inlinenoexcept |
Add default arguments to the argument parser.
| arg_discriminators | A list of default positional argument discriminators. |
Definition at line 266 of file argument_parser.hpp.
|
inlinenoexcept |
Add default arguments to the argument parser.
| arg_discriminators | A list of default positional argument discriminators. |
Definition at line 277 of file argument_parser.hpp.
|
inlinenoexcept |
Check whether the parser has finalized parsing its own arguments.
true if parsing was completed for the parser, false otherwise. Definition at line 724 of file argument_parser.hpp.
|
inlinenoexcept |
Check if the given argument has a value.
| arg_name | The name of the argument. |
true if the argument has a value, false otherwise. Definition at line 756 of file argument_parser.hpp.
|
inlinenoexcept |
Check whether this parser was invoked.
true if the parser was selected when parsing the command-line arguments, false otherwise. Definition at line 716 of file argument_parser.hpp.
|
inlinenoexcept |
Check if a specific argument was used in the command-line.
| arg_name | The name of the argument. |
true if the argument was used on the command line, false otherwise. Definition at line 746 of file argument_parser.hpp.
|
inlinenoexcept |
Returns the parser's name.
Definition at line 692 of file argument_parser.hpp.
|
delete |
|
delete |
|
inline |
Parses the command-line arguments.
| AR | The argument range type. |
| argv_rng | A range of command-line argument values. |
argv_rng must be a std::ranges::forward_range with a value type convertible to std::string. | ap::invalid_configuration,ap::parsing_failure |
parse_args function assumes that the program name argument has already been discarded. Definition at line 556 of file argument_parser.hpp.
Parses the command-line arguments.
Equivalent to:
| argc | Number of command-line arguments. |
| argv | Array of command-line argument values. |
| ap::invalid_configuration,ap::parsing_failure |
Definition at line 543 of file argument_parser.hpp.
|
inline |
Parses the known command-line arguments.
add_positional_argumentadd_optional_argumentadd_flag| AR | The argument range type. |
| argv_rng | A range of command-line argument values. |
argv_rng must be a std::ranges::forward_range with a value type convertible to std::string. | ap::invalid_configuration,ap::parsing_failure |
parse_known_args function assumes that the program name argument already been discarded. Definition at line 643 of file argument_parser.hpp.
Parses the known command-line arguments.
Equivalent to:
An argument is considered "known" if it was defined using the parser's argument declaraion methods:
add_positional_argumentadd_optional_argumentadd_flag| argc | Number of command-line arguments. |
| argv | Array of command-line argument values. |
| ap::invalid_configuration,ap::parsing_failure |
Definition at line 624 of file argument_parser.hpp.
|
inlinenoexcept |
Prints the argument parser's help message to an output stream.
| verbose | The verbosity mode value. |
| os | The output stream. |
Definition at line 853 of file argument_parser.hpp.
|
inlinenoexcept |
Prints the argument parser's version info to an output stream.
If no version was spcified for the parser, unspecified will be printed.
| os | The output stream. |
Definition at line 876 of file argument_parser.hpp.
|
inlinenoexcept |
Set the program description.
| description | The description of the program. |
Definition at line 220 of file argument_parser.hpp.
|
inlinenoexcept |
Definition at line 707 of file argument_parser.hpp.
|
inlinenoexcept |
Set the program version.
| version | The version of the program. |
Definition at line 196 of file argument_parser.hpp.
|
inline |
Set the program version.
| version | The version of the program. |
Definition at line 206 of file argument_parser.hpp.
|
inlinenoexcept |
Returns the deepest invoked parser.
Definition at line 732 of file argument_parser.hpp.
|
inline |
Parses the command-line arguments and exits on error.
Calls parse_args(argv_rng) 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_rng | A range of command-line argument values. |
argv_rng must be a std::ranges::forward_range with a value type convertible to std::string. try_parse_args function assumes that the program name argument has already been discarded. Definition at line 595 of file argument_parser.hpp.
Parses the command-line arguments and exits on error.
Equivalent to:
| argc | Number of command-line arguments. |
| argv | Array of command-line argument values. |
Definition at line 578 of file argument_parser.hpp.
|
inline |
Parses known the command-line arguments and exits on error.
Calls parse_known_args(argv_rng) 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. Otherwise the result of parse_known_args(argv_rng) is returned.
| AR | The argument range type. |
| argv_rng | A range of command-line argument values. |
argv_rng must be a std::ranges::forward_range with a value type convertible to std::string. try_parse_known_args function assumes that the program name argument has already been discarded. Definition at line 680 of file argument_parser.hpp.
|
inline |
Parses the known command-line arguments and exits on error.
Equivalent to:
| argc | Number of command-line arguments. |
| argv | Array of command-line argument values. |
Definition at line 662 of file argument_parser.hpp.
|
inlinenoexcept |
Set the unknown argument flags handling policy.
| policy | The unknown arguments policy value. |
ap::unknown_policy::fail. Definition at line 242 of file argument_parser.hpp.
|
inline |
Get the value of the given argument.
| T | Type of the argument value. |
| arg_name | The name of the argument. |
| ap::lookup_failure,ap::type_error |
Definition at line 779 of file argument_parser.hpp.
|
inline |
Get the value of the given argument, if it has any, or a fallback value, if not.
| T | Type of the argument value. |
| U | The default value type. |
| arg_name | The name of the argument. |
| fallback_value | The fallback value. |
| ap::lookup_failure,ap::type_error |
Definition at line 803 of file argument_parser.hpp.
|
inline |
Get all values of the given argument.
| T | Type of the argument values. |
| arg_name | The name of the argument. |
| ap::lookup_failure,ap::type_error |
Definition at line 830 of file argument_parser.hpp.
|
inlinenoexcept |
Set the verbosity mode.
false. | v | The verbosity mode value. |
Definition at line 231 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_help(_verbose, os) call, where _verbose is the inner verbosity mode, which can be set with the verbose function.
| os | The output stream. |
| parser | The argument parser to print. |
Definition at line 891 of file argument_parser.hpp.
|
private |
The list of argument groups.
Definition at line 1562 of file argument_parser.hpp.
A flag indicating whether the parsing process has been finalized.
Definition at line 1569 of file argument_parser.hpp.
|
staticconstexprprivate |
Definition at line 1574 of file argument_parser.hpp.
Definition at line 1573 of file argument_parser.hpp.
|
private |
The optional argument group.
Definition at line 1564 of file argument_parser.hpp.
|
private |
The positional argument group.
Definition at line 1563 of file argument_parser.hpp.
|
staticconstexprprivate |
Definition at line 1575 of file argument_parser.hpp.
|
private |
A flag indicating whether the parser has been invoked to parse arguments.
Definition at line 1567 of file argument_parser.hpp.
|
private |
The name of the parser.
Definition at line 1552 of file argument_parser.hpp.
|
private |
The list of optional arguments.
Definition at line 1561 of file argument_parser.hpp.
|
private |
The list of positional arguments.
Definition at line 1560 of file argument_parser.hpp.
Definition at line 1571 of file argument_parser.hpp.
|
private |
The description of the program.
Definition at line 1556 of file argument_parser.hpp.
|
private |
The name of the program in the format "<parent-parser-names>... <program-name>".
Definition at line 1554 of file argument_parser.hpp.
|
private |
The version of the program.
Definition at line 1555 of file argument_parser.hpp.
|
staticconstexprprivate |
Definition at line 1572 of file argument_parser.hpp.
|
private |
The list of subparsers.
Definition at line 1565 of file argument_parser.hpp.
|
private |
Policy for unknown arguments.
Definition at line 1558 of file argument_parser.hpp.
Verbosity flag.
Definition at line 1557 of file argument_parser.hpp.