15#include "util/concepts.hpp"
21struct argument_test_fixture;
57template <argument_type ArgT, util::c_argument_value_type T = std::
string>
106 [[nodiscard]]
const std::optional<std::string>&
help() const noexcept
override {
111 [[nodiscard]]
bool is_hidden() const noexcept
override {
131 [[nodiscard]]
bool is_greedy() const noexcept
override {
166 std::format(
"A suppressing argument [{}] cannot be required!", this->
_name.
str())
182 "A required argument [{}] cannot suppress argument checks!", this->
_name.
str()
198 "A required argument [{}] cannot suppress argument group checks!", this->
_name.
str()
266 template <action::util::c_value_action_specifier AS,
typename F>
283 template <action::util::c_flag_action_specifier AS,
typename F>
300 template <util::c_range_of<value_type, util::type_val
idator::convertible> CR>
304 for (
const auto& choice :
choices)
305 this->
_choices.emplace_back(choice);
318 return this->choices<>(
choices);
342 template <util::c_range_of<value_type, util::type_val
idator::convertible> CR>
362 return this->default_values<>(
values);
387 template <util::c_range_of<value_type, util::type_val
idator::convertible> CR>
405 return this->implicit_values<>(
values);
422 friend struct ::ap_testing::argument_test_fixture;
434 template <
typename _T>
442 template <
typename _T>
444 std::conditional_t<type == argument_type::positional, _T, none_type>;
448 template <
typename _T>
450 std::conditional_t<type == argument_type::optional, _T, none_type>;
468 bld.
add_param(
"suppress arg checks",
"true");
470 bld.
add_param(
"suppress group checks",
"true");
478 "default value(s)", util::any_range_cast_view<value_type>(this->_default_values)
484 util::any_range_cast_view<value_type>(this->_implicit_values)
505 [[nodiscard]]
bool is_used() const noexcept
override {
506 return this->
count() > 0ull;
514 [[nodiscard]] std::size_t
count() const noexcept
override {
533 [[nodiscard]]
bool has_value() const noexcept
override {
539 return not this->
_values.empty();
549 if (this->
_values.empty() and this->_has_predefined_values_impl())
550 return std::weak_ordering::equivalent;
560 [[nodiscard]]
const std::any&
value()
const override {
565 throw std::logic_error(
566 std::format(
"No values parsed for argument '{}'.", this->
_name.
str())
573 [[nodiscard]]
const std::vector<std::any>&
values()
const override {
579 [[nodiscard]]
const std::vector<std::any>&
_values_impl() const noexcept
590 [[nodiscard]]
const std::vector<std::any>&
_values_impl() const noexcept
599 catch (
const std::logic_error&) {
640 throw(std::logic_error(std::format(
641 "No implicit values specified for argument '{}'.", this->
_name.
str()
649 throw(std::logic_error(
650 std::format(
"No default values specified for argument '{}'.", this->
_name.
str())
658 return not std::is_gt(this->
_values.size() + 1ull <=> this->_nargs_range);
680 "Cannot set values for a none-type argument '{}' (value: '{}')",
707 if (not (std::istringstream(str_value) >>
value))
709 "Cannot parse value `{}` for argument [{}].", str_value, this->
_name.
str()
715 "Value `{}` is not a valid choice for argument [{}].", str_value, this->
_name.
str()
720 std::visit(apply_visitor,
action);
767template <util::c_argument_value_type T = std::
string>
775template <util::c_argument_value_type T = std::
string>
Defines the base argument class and common utility.
Represents a command-line argument, either positional or optional.
argument & action(F &&action) noexcept
Set the on-flag action for the argument.
std::vector< std::any > _values
The argument's parsed values.
std::conditional_t< type==argument_type::positional, _T, none_type > positional_specific_type
The argument's positional-argument-specific type alias.
bool suppresses_group_checks() const noexcept override
static constexpr argument_type type
The argument's type discriminator.
argument & action(F &&action) noexcept
Set the value action for the argument.
bool _greedy
The argument's greedy attribute value.
action::util::value_action_variant_type< T > value_action_type
The argument's value action type alias.
argument & implicit_values(const CR &values) noexcept
Add implicit values for the optional argument.
const std::vector< std::any > & _predefined_values() const
T value_type
The argument's value type alias.
argument(const detail::argument_name &name)
Optional argument constructor.
const std::vector< std::any > & _values_impl() const noexcept
bool is_greedy() const noexcept override
bool mark_used() override
Mark the optional argument as used.
const std::any & value() const override
argument & default_values(const CR &values) noexcept
Add default values for the argument.
bool _is_valid_choice(const value_type &value) const noexcept
value_arg_specific_type< optional_specific_type< std::vector< std::any > > > _implicit_values
The optional argument's implicit value list.
bool is_required() const noexcept override
bool has_value() const noexcept override
bool _required
The argument's required attribute value.
const ap::detail::argument_name _name
The argument's name.
std::weak_ordering nvalues_ordering() const noexcept override
argument & nargs(const count_type n) noexcept
Set the nargs range for the argument.
bool _set_value_impl(const std::string &str_value)
The implementation of the set_value method for non-none-type arguments.
bool is_positional() const noexcept override
Checks if the argument is positional.
argument & suppress_arg_checks(const bool value=true)
Enable/disable suppressing argument checks for other arguments.
argument & nargs(const count_type lower, const count_type upper) noexcept
Set the nargs range for the optional argument.
bool has_parsed_values() const noexcept override
bool _accepts_further_values() const noexcept
optional_specific_type< std::vector< flag_action_type > > _flag_actions
The optional argument's flag actions collection.
nargs::count_type count_type
The argument's count type alias.
nargs::range _nargs_range
The argument's nargs range attribute value.
bool is_used() const noexcept override
argument & default_values(std::initializer_list< value_type > values) noexcept
Add default values for the argument.
argument & implicit_values(std::initializer_list< value_type > values) noexcept
Add implicit values for the optional argument.
bool _has_predefined_values_impl() const noexcept
bool suppresses_arg_checks() const noexcept override
bool is_optional() const noexcept override
Checks if the argument is optional.
const std::optional< std::string > & help() const noexcept override
std::optional< std::string > _help_msg
The argument's help message.
argument & required(const bool value=true)
Set the required attribute of the argument.
value_arg_specific_type< std::vector< value_action_type > > _value_actions
The argument's value actions collection.
argument & greedy(const bool value=true) noexcept
Set the greedy attribute of the argument.
argument & choices(const std::convertible_to< value_type > auto &... choices) noexcept
Add the choices for the argument.
bool _has_predefined_values_impl() const noexcept
bool _hidden
The argument's hidden attribute value.
value_arg_specific_type< std::vector< std::any > > _default_values
The argument's default value list.
typename action_type::on_flag::type flag_action_type
The argument's flag action type alias.
argument & choices(std::initializer_list< value_type > choices) noexcept
Add the choices for the argument.
const std::vector< std::any > & values() const override
argument & suppress_group_checks(const bool value=true)
Enable/disable suppressing argument group checks.
bool is_hidden() const noexcept override
std::size_t count() const noexcept override
std::conditional_t< type==argument_type::optional, _T, none_type > optional_specific_type
The argument's optional-argument-specific type alias.
static constexpr nargs::range _default_nargs_range
bool has_predefined_values() const noexcept override
static constexpr nargs::range _default_nargs_range_actual
argument & nargs(const nargs::range &range) noexcept
Set the nargs range for the argument.
bool _suppress_group_checks
The argument's suppress_group_checks attribute value.
argument & help(std::string_view help_msg) noexcept
Set the help message for the argument.
bool _suppress_arg_checks
The argument's suppress_arg_checks attribute value.
static constexpr bool _default_required
optional_specific_type< std::size_t > _count
The argument's value count.
detail::help_builder help_builder(const bool verbose) const noexcept override
Creates a help message builder object for the argument.
value_arg_specific_type< std::vector< value_type > > _choices
The argument's valid choices collection.
const std::vector< std::any > & _values_impl() const noexcept
bool set_value(const std::string &str_value) override
Set the value for the optional argument.
argument(const detail::argument_name &name)
Positional argument constructor.
const ap::detail::argument_name & name() const noexcept override
argument & implicit_values(const std::convertible_to< value_type > auto &... values) noexcept
Add a implicit values for the optional argument.
argument & default_values(const std::convertible_to< value_type > auto &... values) noexcept
Add default values for the argument.
std::conditional_t< util::c_is_none< value_type >, none_type, _T > value_arg_specific_type
Type alias for value-argument-specific types.
argument & hidden(const bool h=true) noexcept
Set the hidden attribute for the argument.
bool _set_value_impl(const std::string &str_value)
The implementation of the set_value method for none-type arguments.
argument & choices(const CR &choices) noexcept
Add the choices for the argument.
Argument class interface.
A help message builder class.
void add_range_param(const std::string ¶m_name, const R &range, const std::string_view delimiter=default_delimiter)
Adds a range parameter descriptor with the given value.
std::vector< parameter_descriptor > params
void add_param(const std::string ¶m_name, const std::string &value)
Adds a parameter descriptor with the given string value.
Argument's number of values managing class.
The concept is satisfied when T is ap::none_type.
The concept is satisfied when T can be constructed from const std::string&.
The concept is satisfied when T overloads the std::ostream operator <<.
typename AS::template type< T > callable_type
Template argument action callable type alias.
Defines structures for creating and formatting help messages.
Defines general action-related helper utility.
std::variant< callable_type< action_type::observe, T >, callable_type< action_type::transform, T >, callable_type< action_type::modify, T > > value_action_variant_type
Template argument action callabla variant type alias.
constexpr range any() noexcept
range class builder function. Creates a range [0, inf].
argument_type
A discriminator type used to specify the type of an argument within the ap::argument class.
Defines the nargs::range class and it's builder functions.
Provides common ranges utility functions.
A visitor structure used to apply value actions.
std::function< void()> type
Structure holding the argument's name.
std::string str() const noexcept
Get a string representation of the argument_name.
Exception type used for invalid configuration of an argument parser or its arguments.
A type representing the absence of a value. This type is used for arguments that should not store any...
Exception type used for errors encountered during the argument parsing operation.
static parsing_failure invalid_nvalues(const detail::argument_name &arg_name, const std::weak_ordering ordering) noexcept