|
koutil
|
Represents a command-line option. More...
#include <option.h>
Public Types | |
| using | result_t = Result |
| using | handle_t = std::function<void(std::optional<std::string_view>, result_t&)> |
| Type alias for option handler function. | |
Public Member Functions | |
| template<void_handle< std::optional< std::string_view >, result_t & > Handle> | |
| option_t (const option_data_t &data, Handle &&handle) | |
| Constructs an option from data and a handler. | |
| bool | required () const |
| Checks if the option is required. | |
| bool | used () const |
| Checks if the option has been used. | |
| auto | long_name () const |
| Gets the long option name. | |
| auto | short_name () const |
| Gets the short option name. | |
| std::string_view | description () const |
| Gets the option description. | |
| bool | has_value () const |
| Checks if the option expects a value. | |
| std::string_view | value_name () const |
| Gets the display name for the option value. | |
| void | process (std::optional< std::string_view > value, result_t &result) |
| Processes the option value using the assigned handler. | |
| void | clear_used () |
| Clears state. | |
Private Attributes | |
| bool | m_has_value |
| bool | m_required |
| bool | m_used = false |
| std::optional< std::string_view > | m_long_name |
| std::optional< char > | m_short_name |
| std::string_view | m_description |
| std::string_view | m_value_name |
| handle_t | m_handle |
Represents a command-line option.
Each option may have a short and/or long name, a description, and an optional handler function. Options can be required or optional, and may accept a value depending on configuration.
The order in which options are added defines their order in the help text, but does not affect command-line parsing behavior.
| using koutil::args::option_t< Result >::handle_t = std::function<void(std::optional<std::string_view>, result_t&)> |
Type alias for option handler function.
| using koutil::args::option_t< Result >::result_t = Result |
|
inlineexplicit |
Constructs an option from data and a handler.
| Handle | Callable type compatible with void(std::optional<std::string_view>, result_t&). |
| data | Option metadata. |
| handle | Function to process the option value. |
|
inline |
Clears state.
|
inlinenodiscard |
Gets the option description.
|
inlinenodiscard |
Checks if the option expects a value.
|
inlinenodiscard |
Gets the long option name.
| void koutil::args::option_t< Result >::process | ( | std::optional< std::string_view > | value, |
| result_t & | result ) |
Processes the option value using the assigned handler.
| value | Option value, if provided. |
| result | Result object to update. |
|
inlinenodiscard |
Checks if the option is required.
|
inlinenodiscard |
Gets the short option name.
|
inlinenodiscard |
Checks if the option has been used.
|
inlinenodiscard |
Gets the display name for the option value.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |