|
CPP-AP 3.0.1
Command-line argument parser for C++20
|
Represents a command-line argument, either positional or optional. More...
#include <argument.hpp>
Public Types | |
| using | value_type = T |
| The argument's value type alias. | |
| using | count_type = nargs::count_type |
| The argument's count type alias. | |
Public Member Functions | |
| argument ()=delete | |
| argument (const detail::argument_name &name) | |
| Positional argument constructor. | |
| argument (const detail::argument_name &name) | |
| Optional argument constructor. | |
| bool | is_positional () const noexcept override |
| Checks if the argument is positional. | |
| bool | is_optional () const noexcept override |
| Checks if the argument is optional. | |
| const ap::detail::argument_name & | name () const noexcept override |
| const std::optional< std::string > & | help () const noexcept override |
| bool | is_hidden () const noexcept override |
| bool | is_required () const noexcept override |
| bool | suppresses_arg_checks () const noexcept override |
| bool | suppresses_group_checks () const noexcept override |
| bool | is_greedy () const noexcept override |
| argument & | help (std::string_view help_msg) noexcept |
| Set the help message for the argument. | |
| argument & | hidden (const bool h=true) noexcept |
Set the hidden attribute for the argument. | |
| argument & | required (const bool value=true) |
Set the required attribute of the argument. | |
| argument & | suppress_arg_checks (const bool value=true) |
| Enable/disable suppressing argument checks for other arguments. | |
| argument & | suppress_group_checks (const bool value=true) |
| Enable/disable suppressing argument group checks. | |
| argument & | greedy (const bool value=true) noexcept |
Set the greedy attribute of the argument. | |
| argument & | nargs (const nargs::range &range) noexcept |
| Set the nargs range for the argument. | |
| argument & | nargs (const count_type n) noexcept |
| Set the nargs range for the argument. | |
| argument & | nargs (const count_type lower, const count_type upper) noexcept |
| Set the nargs range for the optional argument. | |
| template<action::util::c_value_action_specifier AS, typename F > requires (not util::c_is_none<value_type>) | |
| argument & | action (F &&action) noexcept |
| Set the value action for the argument. | |
| template<action::util::c_flag_action_specifier AS, typename F > requires (type == argument_type::optional) | |
| argument & | action (F &&action) noexcept |
| Set the on-flag action for the argument. | |
| template<util::c_range_of< value_type, util::type_validator::convertible > CR> requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>) | |
| argument & | choices (const CR &choices) noexcept |
| Add the choices for the argument. | |
| argument & | choices (std::initializer_list< value_type > choices) noexcept |
| Add the choices for the argument. | |
| argument & | choices (const std::convertible_to< value_type > auto &... choices) noexcept |
| Add the choices for the argument. | |
| template<util::c_range_of< value_type, util::type_validator::convertible > CR> requires (not util::c_is_none<value_type> and std::equality_comparable<value_type>) | |
| argument & | default_values (const CR &values) noexcept |
| Add default values for the argument. | |
| argument & | default_values (std::initializer_list< value_type > values) noexcept |
| Add default values for the argument. | |
| argument & | default_values (const std::convertible_to< value_type > auto &... values) noexcept |
| Add default values for the argument. | |
| template<util::c_range_of< value_type, util::type_validator::convertible > CR> requires (not util::c_is_none<value_type> and type == argument_type::optional) | |
| argument & | implicit_values (const CR &values) noexcept |
| Add implicit values for the optional argument. | |
| argument & | implicit_values (std::initializer_list< value_type > values) noexcept |
| Add implicit values for the optional argument. | |
| argument & | implicit_values (const std::convertible_to< value_type > auto &... values) noexcept |
| Add a implicit values for the optional argument. | |
Public Member Functions inherited from ap::detail::argument_base | |
| virtual | ~argument_base ()=default |
Static Public Attributes | |
| static constexpr argument_type | type = ArgT |
| The argument's type discriminator. | |
Private Types | |
| using | value_action_type = action::util::value_action_variant_type< T > |
| The argument's value action type alias. | |
| using | flag_action_type = typename action_type::on_flag::type |
| The argument's flag action type alias. | |
| template<typename _T > | |
| using | value_arg_specific_type = std::conditional_t< util::c_is_none< value_type >, none_type, _T > |
| Type alias for value-argument-specific types. | |
| template<typename _T > | |
| using | positional_specific_type = std::conditional_t< type==argument_type::positional, _T, none_type > |
| The argument's positional-argument-specific type alias. | |
| template<typename _T > | |
| using | optional_specific_type = std::conditional_t< type==argument_type::optional, _T, none_type > |
| The argument's optional-argument-specific type alias. | |
Private Member Functions | |
| detail::help_builder | help_builder (const bool verbose) const noexcept override |
| Creates a help message builder object for the argument. | |
| bool | mark_used () override |
| Mark the optional argument as used. | |
| bool | is_used () const noexcept override |
| std::size_t | count () const noexcept override |
| bool | set_value (const std::string &str_value) override |
| Set the value for the optional argument. | |
| bool | has_value () const noexcept override |
| bool | has_parsed_values () const noexcept override |
| bool | has_predefined_values () const noexcept override |
| std::weak_ordering | nvalues_ordering () const noexcept override |
| const std::any & | value () const override |
| const std::vector< std::any > & | values () const override |
| const std::vector< std::any > & | _values_impl () const noexcept |
| const std::vector< std::any > & | _values_impl () const noexcept |
| bool | _has_predefined_values_impl () const noexcept |
| bool | _has_predefined_values_impl () const noexcept |
| const std::vector< std::any > & | _predefined_values () const |
| bool | _accepts_further_values () const noexcept |
| bool | _is_valid_choice (const value_type &value) const noexcept |
| bool | _set_value_impl (const std::string &str_value) |
The implementation of the set_value method for none-type arguments. | |
| bool | _set_value_impl (const std::string &str_value) |
The implementation of the set_value method for non-none-type arguments. | |
Private Attributes | |
| const ap::detail::argument_name | _name |
| The argument's name. | |
| std::optional< std::string > | _help_msg |
| The argument's help message. | |
| nargs::range | _nargs_range |
| The argument's nargs range attribute value. | |
| value_arg_specific_type< std::vector< std::any > > | _default_values |
| The argument's default value list. | |
| value_arg_specific_type< optional_specific_type< std::vector< std::any > > > | _implicit_values |
| The optional argument's implicit value list. | |
| value_arg_specific_type< std::vector< value_type > > | _choices |
| The argument's valid choices collection. | |
| optional_specific_type< std::vector< flag_action_type > > | _flag_actions |
| The optional argument's flag actions collection. | |
| value_arg_specific_type< std::vector< value_action_type > > | _value_actions |
| The argument's value actions collection. | |
| bool | _required: 1 |
The argument's required attribute value. | |
| bool | _suppress_arg_checks: 1 = false |
The argument's suppress_arg_checks attribute value. | |
| bool | _suppress_group_checks: 1 = false |
The argument's suppress_group_checks attribute value. | |
| bool | _greedy: 1 = false |
The argument's greedy attribute value. | |
| bool | _hidden: 1 = false |
The argument's hidden attribute value. | |
| optional_specific_type< std::size_t > | _count |
| The argument's value count. | |
| std::vector< std::any > | _values |
| The argument's parsed values. | |
Static Private Attributes | |
| static constexpr bool | _default_required = (type == argument_type::positional) |
| static constexpr nargs::range | _default_nargs_range |
| static constexpr nargs::range | _default_nargs_range_actual |
Additional Inherited Members |
Represents a command-line argument, either positional or optional.
This class defines the behaviour of command-line arguments - both positional and optional, depending on the given type discriminator.
add_positional_argument add_optional_argument add_flag Example usage:
| ArgT | The argument type, either ap::argument_type::positional or ap::argument_type::optional. |
| T | The value type accepted by the argument (defaults to std::string). |
Definition at line 58 of file argument.hpp.
| using ap::argument< ArgT, T >::count_type = nargs::count_type |
The argument's count type alias.
Definition at line 61 of file argument.hpp.
|
private |
The argument's flag action type alias.
Definition at line 430 of file argument.hpp.
|
private |
The argument's optional-argument-specific type alias.
| _T | The actual type used if the argument's type is argument_type::optional. |
Definition at line 449 of file argument.hpp.
|
private |
The argument's positional-argument-specific type alias.
| _T | The actual type used if the argument's type is argument_type::positional. |
Definition at line 443 of file argument.hpp.
|
private |
The argument's value action type alias.
Definition at line 427 of file argument.hpp.
|
private |
Type alias for value-argument-specific types.
Definition at line 435 of file argument.hpp.
| using ap::argument< ArgT, T >::value_type = T |
The argument's value type alias.
Definition at line 60 of file argument.hpp.
|
delete |
|
inline |
Positional argument constructor.
| name | The name of the positional argument. |
type is argument_type::positional. Definition at line 72 of file argument.hpp.
|
inline |
Optional argument constructor.
| name | The name of the optional argument. |
type is argument_type::optional. Definition at line 81 of file argument.hpp.
|
inlineprivatenoexcept |
true if the argument accepts further values, false otherwise. Definition at line 657 of file argument.hpp.
|
inlineprivatenoexcept |
true if the argument has a predefined value, false otherwise. Definition at line 605 of file argument.hpp.
|
inlineprivatenoexcept |
true if the argument has a predefined value, false otherwise. value_type is not none_type. Definition at line 617 of file argument.hpp.
|
inlineprivatenoexcept |
true if the given value is a valid choice for the argument, false otherwise. Definition at line 663 of file argument.hpp.
|
inlineprivate |
| std::logic_error | if no predefined values are available. |
value_type is not none_type. Definition at line 634 of file argument.hpp.
|
inlineprivate |
The implementation of the set_value method for none-type arguments.
| str_value | The string value to set. |
| ap::parsing_failure |
set_value should never be called for a none-type argument). Definition at line 676 of file argument.hpp.
|
inlineprivate |
The implementation of the set_value method for non-none-type arguments.
true if the argument accepts further values, false otherwise. | str_value | The string value to set. |
| ap::parsing_failure | if: |
| - | the argument does not accept further values (nargs limit exceeded). |
| - | the value cannot be parsed to the argument's value_type. |
| - | the value is not a valid choice for the argument (if choices are defined). |
value_type is not none_type. Definition at line 696 of file argument.hpp.
|
inlineprivatenoexcept |
Definition at line 579 of file argument.hpp.
|
inlineprivatenoexcept |
value_type is not none_type. Definition at line 590 of file argument.hpp.
|
inlinenoexcept |
Set the value action for the argument.
| AS | The action specifier type (see ap/action/type.hpp). |
| F | The type of the action function. |
| action | The action callable. |
value_type is not none_type. AS is a valid value action specifier: action_type::observe, action_type::transform, action_type::modify. Definition at line 267 of file argument.hpp.
|
inlinenoexcept |
Set the on-flag action for the argument.
| AS | The action specifier type (see ap/action/types.hpp). |
| F | The type of the action function. |
| action | The action callable. |
AS is action_type::on_flag. Definition at line 284 of file argument.hpp.
|
inlinenoexcept |
Add the choices for the argument.
| CR | The choices range type. |
| choices | The range of valid choices for the argument. |
value_type must not be none_type and must be equality comparable CR must be a range such that its value type is convertible to the argument's value_type Definition at line 301 of file argument.hpp.
|
inlinenoexcept |
Add the choices for the argument.
| Args | The types of the choices. |
| choices | The list of valid choices for the argument. |
value_type is not none_type and is equality comparable. Definition at line 328 of file argument.hpp.
|
inlinenoexcept |
Add the choices for the argument.
| choices | The list of valid choices for the argument. |
value_type is not none_type and is equality comparable. Definition at line 315 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
0 (not used) or 1 (used). Implements ap::detail::argument_base.
Definition at line 514 of file argument.hpp.
|
inlinenoexcept |
Add default values for the argument.
| values | The default values to add. |
required attribute to false. value_type is not none_type. Definition at line 343 of file argument.hpp.
|
inlinenoexcept |
Add default values for the argument.
| values | The default values to add. |
required attribute to false. value_type is not none_type. Definition at line 372 of file argument.hpp.
|
inlinenoexcept |
Add default values for the argument.
| values | The default values to add. |
required attribute to false. value_type is not none_type. Definition at line 359 of file argument.hpp.
|
inlinenoexcept |
Set the greedy attribute of the argument.
| value | The attribute value (default: true). |
value_type is not none_type. Definition at line 211 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
true if parsed values are available for the argument, false otherwise. Implements ap::detail::argument_base.
Definition at line 538 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
true if the argument has predefined values, false otherwise. Implements ap::detail::argument_base.
Definition at line 543 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
true if the argument has a value, false otherwise. Implements ap::detail::argument_base.
Definition at line 533 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
Implements ap::detail::argument_base.
Definition at line 106 of file argument.hpp.
|
inlinenoexcept |
Set the help message for the argument.
| help_msg | The help message to set. |
Definition at line 142 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
Creates a help message builder object for the argument.
| verbose | The verbosity mode value. |
verbose parameter is set to true all non-default parameters will be included in the output, Implements ap::detail::argument_base.
Definition at line 458 of file argument.hpp.
|
inlinenoexcept |
Set the hidden attribute for the argument.
| h | The attribute value. |
Definition at line 152 of file argument.hpp.
|
inlinenoexcept |
Add implicit values for the optional argument.
| CR | The choices range type. |
| values | The range of implicit values to set. |
value_type is not none_type. Definition at line 388 of file argument.hpp.
|
inlinenoexcept |
Add a implicit values for the optional argument.
| values | The implicit values to set. |
value_type is not none_type. Definition at line 414 of file argument.hpp.
|
inlinenoexcept |
Add implicit values for the optional argument.
| values | The initializer list of implicit values to set. |
value_type is not none_type. Definition at line 402 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
true if the argument is greedy, false otherwise. Implements ap::detail::argument_base.
Definition at line 131 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
true if the argument is hidden, false otherwise Implements ap::detail::argument_base.
Definition at line 111 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
Checks if the argument is optional.
true if the argument's type is argument_type::optional, false otherwise. Implements ap::detail::argument_base.
Definition at line 96 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
Checks if the argument is positional.
true if the argument's type is argument_type::positional, false otherwise. Implements ap::detail::argument_base.
Definition at line 90 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
true if the argument is required, false otherwise Implements ap::detail::argument_base.
Definition at line 116 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
true if the argument is used, false otherwise. Implements ap::detail::argument_base.
Definition at line 505 of file argument.hpp.
|
inlineoverrideprivatevirtual |
Mark the optional argument as used.
true if the argument accepts further values, false otherwise. Implements ap::detail::argument_base.
Definition at line 494 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
Implements ap::detail::argument_base.
Definition at line 101 of file argument.hpp.
|
inlinenoexcept |
Set the nargs range for the optional argument.
| lower | The lower bound for the nargs range attribute. |
| upper | The upper bound for the nargs range attribute. |
value_type is not none_type. Definition at line 250 of file argument.hpp.
|
inlinenoexcept |
Set the nargs range for the argument.
| n | The exact bound for the nargs range attribute. |
value_type is not none_type. Definition at line 237 of file argument.hpp.
|
inlinenoexcept |
Set the nargs range for the argument.
| range | The attribute value. |
value_type is not none_type. Definition at line 224 of file argument.hpp.
|
inlineoverrideprivatevirtualnoexcept |
Implements ap::detail::argument_base.
Definition at line 548 of file argument.hpp.
|
inline |
Set the required attribute of the argument.
| value | The attribute value (default: true). |
| ap::invalid_configuration | if the argument is configured to suppress argument/group checks. |
Definition at line 163 of file argument.hpp.
|
inlineoverrideprivatevirtual |
Set the value for the optional argument.
| str_value | The string value to use. |
true if the argument accepts further values, false otherwise. | ap::parsing_failure |
Implements ap::detail::argument_base.
Definition at line 527 of file argument.hpp.
|
inline |
Enable/disable suppressing argument checks for other arguments.
| value | The attribute value (default: true). |
| ap::invalid_configuration | if the argument is configured to be required. |
Definition at line 179 of file argument.hpp.
|
inline |
Enable/disable suppressing argument group checks.
| value | The attribute value (default: true). |
| ap::invalid_configuration | if the argument is configured to be required. |
Definition at line 195 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
true if argument checks suppressing is enabled for the argument, false otherwise. Implements ap::detail::argument_base.
Definition at line 121 of file argument.hpp.
|
inlineoverridevirtualnoexcept |
true if argument group checks suppressing is enabled for the argument, false otherwise. Implements ap::detail::argument_base.
Definition at line 126 of file argument.hpp.
|
inlineoverrideprivatevirtual |
| std::logic_error | if no values are available. |
Implements ap::detail::argument_base.
Definition at line 560 of file argument.hpp.
|
inlineoverrideprivatevirtual |
Implements ap::detail::argument_base.
Definition at line 573 of file argument.hpp.
|
private |
The argument's valid choices collection.
Definition at line 735 of file argument.hpp.
|
private |
The argument's value count.
Definition at line 751 of file argument.hpp.
|
staticconstexprprivate |
Definition at line 756 of file argument.hpp.
|
staticconstexprprivate |
Definition at line 758 of file argument.hpp.
|
staticconstexprprivate |
Definition at line 755 of file argument.hpp.
|
private |
The argument's default value list.
Definition at line 731 of file argument.hpp.
|
private |
The optional argument's flag actions collection.
Definition at line 737 of file argument.hpp.
|
private |
The argument's greedy attribute value.
Definition at line 746 of file argument.hpp.
|
private |
The argument's help message.
Definition at line 728 of file argument.hpp.
|
private |
The argument's hidden attribute value.
Definition at line 747 of file argument.hpp.
|
private |
The optional argument's implicit value list.
Definition at line 733 of file argument.hpp.
|
private |
The argument's name.
Definition at line 727 of file argument.hpp.
|
private |
The argument's nargs range attribute value.
Definition at line 729 of file argument.hpp.
|
private |
The argument's required attribute value.
Definition at line 741 of file argument.hpp.
|
private |
The argument's suppress_arg_checks attribute value.
Definition at line 742 of file argument.hpp.
|
private |
The argument's suppress_group_checks attribute value.
Definition at line 744 of file argument.hpp.
|
private |
The argument's value actions collection.
Definition at line 739 of file argument.hpp.
|
private |
The argument's parsed values.
Definition at line 752 of file argument.hpp.
|
staticconstexpr |
The argument's type discriminator.
Definition at line 63 of file argument.hpp.