Builder for creating command-line options.
More...
#include <option_builder.h>
template<extends_result Result = result_base_t>
class koutil::args::option_builder_t< Result >
Builder for creating command-line options.
Provides an interface to construct an option_t instance. The builder allows setting names, description, flags, and a handler function.
Example:
.description("Output file path")
.has_value()
.required()
.handle([](
auto value,
result_t& r) { ... })
option_t build() &&
Builds the option with the configured properties.
Definition option_builder.h:102
Result result_t
Definition option_builder.h:31
option_builder_t(char short_name, std::string_view long_name)
Constructs a builder with both short and long names.
Definition option_builder.h:39
◆ option_t
template<extends_result Result = result_base_t>
◆ result_t
template<extends_result Result = result_base_t>
◆ option_builder_t() [1/3]
template<extends_result Result = result_base_t>
Constructs a builder with both short and long names.
- Parameters
-
| short_name | Short name (without "-"). |
| long_name | Long name (without "--"). |
◆ option_builder_t() [2/3]
template<extends_result Result = result_base_t>
Constructs a builder with only a short name.
- Parameters
-
| short_name | Short name (without "-"). |
◆ option_builder_t() [3/3]
template<extends_result Result = result_base_t>
Constructs a builder with only a long name.
- Parameters
-
| long_name | Long name (without "--"). |
◆ build() [1/2]
template<extends_result Result = result_base_t>
Builds the option with the configured properties.
- Returns
- Constructed option.
◆ build() [2/2]
template<extends_result Result = result_base_t>
template<void_handle< std::optional< std::string_view >,
result_t & > Handle>
Builds the option with an explicit handler.
- Template Parameters
-
| Handle | Callable type compatible with void(std::optional<std::string_view>, result_t&). |
- Parameters
-
| handle | Function to handle the option’s value. |
- Returns
- Constructed option.
◆ description()
template<extends_result Result = result_base_t>
Sets the option description.
- Parameters
-
| description | Description text. |
- Returns
- Builder.
◆ handle()
template<extends_result Result = result_base_t>
template<void_handle< std::optional< std::string_view >,
result_t & > Handle>
Assigns a handler function to the option.
- Template Parameters
-
| Handle | Callable type compatible with void(std::optional<std::string_view>, result_t&). |
- Parameters
-
| handle | Function to handle the option’s value. |
- Returns
- Builder.
◆ has_value()
template<extends_result Result = result_base_t>
Marks the option as one that expects a value.
- Parameters
-
| value | True if it has a value. |
- Returns
- Builder.
◆ required()
template<extends_result Result = result_base_t>
Marks the option as required.
- Parameters
-
| required | True if required. |
- Returns
- Builder.
◆ m_data
template<extends_result Result = result_base_t>
◆ m_handle
template<extends_result Result = result_base_t>
The documentation for this class was generated from the following file: