koutil
Loading...
Searching...
No Matches
koutil::args::option_t< Result > Class Template Reference

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
 

Detailed Description

template<extends_result Result = result_base_t>
class koutil::args::option_t< Result >

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.

Member Typedef Documentation

◆ handle_t

template<extends_result Result = result_base_t>
using koutil::args::option_t< Result >::handle_t = std::function<void(std::optional<std::string_view>, result_t&)>

Type alias for option handler function.

◆ result_t

template<extends_result Result = result_base_t>
using koutil::args::option_t< Result >::result_t = Result

Constructor & Destructor Documentation

◆ option_t()

template<extends_result Result = result_base_t>
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
koutil::args::option_t< Result >::option_t ( const option_data_t & data,
Handle && handle )
inlineexplicit

Constructs an option from data and a handler.

Template Parameters
HandleCallable type compatible with void(std::optional<std::string_view>, result_t&).
Parameters
dataOption metadata.
handleFunction to process the option value.

Member Function Documentation

◆ clear_used()

template<extends_result Result = result_base_t>
void koutil::args::option_t< Result >::clear_used ( )
inline

Clears state.

◆ description()

template<extends_result Result = result_base_t>
std::string_view koutil::args::option_t< Result >::description ( ) const
inlinenodiscard

Gets the option description.

Returns
Option description.

◆ has_value()

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::has_value ( ) const
inlinenodiscard

Checks if the option expects a value.

Returns
True if the option expects a value.

◆ long_name()

template<extends_result Result = result_base_t>
auto koutil::args::option_t< Result >::long_name ( ) const
inlinenodiscard

Gets the long option name.

Returns
Long name (without "--"), if present.

◆ process()

template<extends_result Result>
void koutil::args::option_t< Result >::process ( std::optional< std::string_view > value,
result_t & result )

Processes the option value using the assigned handler.

Parameters
valueOption value, if provided.
resultResult object to update.

◆ required()

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::required ( ) const
inlinenodiscard

Checks if the option is required.

Returns
True if the option is required.

◆ short_name()

template<extends_result Result = result_base_t>
auto koutil::args::option_t< Result >::short_name ( ) const
inlinenodiscard

Gets the short option name.

Returns
Short name (without "-"), if present.

◆ used()

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::used ( ) const
inlinenodiscard

Checks if the option has been used.

Returns
True if the option was used during parsing.

◆ value_name()

template<extends_result Result = result_base_t>
std::string_view koutil::args::option_t< Result >::value_name ( ) const
inlinenodiscard

Gets the display name for the option value.

Returns
Option value name.

Member Data Documentation

◆ m_description

template<extends_result Result = result_base_t>
std::string_view koutil::args::option_t< Result >::m_description
private

◆ m_handle

template<extends_result Result = result_base_t>
handle_t koutil::args::option_t< Result >::m_handle
private

◆ m_has_value

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::m_has_value
private

◆ m_long_name

template<extends_result Result = result_base_t>
std::optional<std::string_view> koutil::args::option_t< Result >::m_long_name
private

◆ m_required

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::m_required
private

◆ m_short_name

template<extends_result Result = result_base_t>
std::optional<char> koutil::args::option_t< Result >::m_short_name
private

◆ m_used

template<extends_result Result = result_base_t>
bool koutil::args::option_t< Result >::m_used = false
private

◆ m_value_name

template<extends_result Result = result_base_t>
std::string_view koutil::args::option_t< Result >::m_value_name
private

The documentation for this class was generated from the following file: