17struct positional_argument_test_fixture;
28template <detail::c_argument_value_type T = std::
string>
49 return this->
_name == other._name;
106 template <detail::c_range_of<value_type, detail::type_val
idator::convertible> CR>
108 requires(std::equality_comparable<value_type>)
110 for (
const auto& choice :
choices)
111 this->
_choices.emplace_back(choice);
122 requires(std::equality_comparable<value_type>)
124 return this->choices<>(
choices);
146 template <action::detail::c_value_action_specifier AS, std::invocable<value_type&> F>
154 friend class ::ap::argument_parser;
160 friend struct ::ap_testing::positional_argument_test_fixture;
180 desc.
add_param(
"bypass required",
"true");
185 desc.
add_param(
"default value", std::any_cast<value_type>(this->_default_value));
200 [[nodiscard]]
bool is_used() const noexcept
override {
201 return this->
_value.has_value();
205 [[nodiscard]] std::size_t
count() const noexcept
override {
216 if (this->
_value.has_value())
224 if (not (std::istringstream(str_value) >>
value))
233 std::visit(apply_visitor,
action);
240 [[nodiscard]]
bool has_value() const noexcept
override {
246 return this->
_value.has_value();
252 return std::weak_ordering::equivalent;
254 return this->
has_value() ? std::weak_ordering::equivalent : std::weak_ordering::less;
261 [[nodiscard]]
const std::any&
value()
const override {
268 throw std::logic_error(
269 std::format(
"No value parsed for the `{}` positional argument.", this->
_name.
str())
277 [[nodiscard]]
const std::vector<std::any>&
values()
const override {
278 throw std::logic_error(
279 std::format(
"Positional argument `{}` has only 1 value.", this->
_name.
str())
Defines the base argument class and common utility.
The positional argument class.
bool set_value(const std::string &str_value) override
Set the value for the positional argument.
std::any _value
Stored value of the positional argument.
positional & bypass_required(const bool br=true) noexcept
Enable/disable bypassing the required attributeattribute for the positional argument.
positional & required(const bool r=true) noexcept
Set the required attribute of the positional argument.
bool operator==(const positional &other) const noexcept
Equality operator for positional argument.
std::weak_ordering nvalues_ordering() const noexcept override
positional & default_value(const std::convertible_to< value_type > auto &default_value) noexcept
Set the default value for the positional argument.
positional & action(F &&action) noexcept
Set the action for the positional argument.
positional & choices(const CR &choices) noexcept
Set the choices for the positional argument.
bool is_used() const noexcept override
bool mark_used() override
Mark the positional argument as used.
action::detail::value_action_variant_type< T > value_action_type
The argument's value action type.
detail::argument_descriptor desc(const bool verbose) const noexcept override
const std::vector< std::any > & values() const override
positional & help(std::string_view help_msg) noexcept
Set the help message for the positional argument.
positional & hidden(const bool h=true) noexcept
Set the hidden attribute for the positional argument.
std::vector< value_action_type > _value_actions
T value_type
The argument's value type.
positional & choices(std::initializer_list< value_type > choices) noexcept
Set the choices for the positional argument.
positional(const detail::argument_name &name)
Constructor for positional argument with the name identifier.
const std::any & value() const override
Get the stored value of the positional argument.
std::size_t count() const noexcept override
bool has_value() const noexcept override
bool has_parsed_values() const noexcept override
std::vector< value_type > _choices
Argument class interface.
const ap::detail::argument_name _name
const ap::detail::argument_name & name() const noexcept
bool bypass_required_enabled() const noexcept
std::optional< std::string > _help_msg
argument_base(const argument_name &name, const bool required=false)
A structure used to represent an argument's description.
void add_param(const std::string ¶m_name, const std::string &value)
Adds a parameter descriptor with the given string value.
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.
The concept is satisfied when T can be constructed from const std::string&.
The concept is satisfied when T overloads the std::ostream operator <<.
Provides the general concept definitions.
typename AS::template type< T > callable_type
Template argument action callable type alias.
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.
bool is_valid_choice(const T &value, const std::vector< T > &choices) noexcept
Checks if the provided choice is valid for the given set of choices.
A visitor structure used to apply value actions.
Structure holding the argument's name.
std::string str() const noexcept
Get a string representation of the argument_name.
static parsing_failure invalid_value(const detail::argument_name &arg_name, const std::string &value) noexcept
static parsing_failure invalid_choice(const detail::argument_name &arg_name, const std::string &value) noexcept
static parsing_failure value_already_set(const detail::argument_name &arg_name) noexcept
Defines general action-related utility.