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

Builder for creating command-line options. More...

#include <option_builder.h>

Public Types

using result_t = Result
 
using option_t = option_t<result_t>
 

Public Member Functions

 option_builder_t (char short_name, std::string_view long_name)
 Constructs a builder with both short and long names.
 
 option_builder_t (char short_name)
 Constructs a builder with only a short name.
 
 option_builder_t (std::string_view long_name)
 Constructs a builder with only a long name.
 
option_builder_t && description (std::string_view description) &&
 Sets the option description.
 
option_builder_t && required (bool required=true) &&
 Marks the option as required.
 
option_builder_t && has_value (bool value=true) &&
 Marks the option as one that expects a value.
 
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
option_builder_t && handle (Handle &&handle) &&
 Assigns a handler function to the option.
 
option_t build () &&
 Builds the option with the configured properties.
 
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
option_t build (Handle &&handle) &&
 Builds the option with an explicit handler.
 

Private Attributes

option_data_t m_data
 
option_t::handle_t m_handle
 

Detailed Description

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:

auto opt = option_builder_t('o', "output")
.description("Output file path")
.has_value()
.required()
.handle([](auto value, result_t& r) { ... })
.build();
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

Member Typedef Documentation

◆ option_t

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

◆ result_t

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

Constructor & Destructor Documentation

◆ option_builder_t() [1/3]

template<extends_result Result = result_base_t>
koutil::args::option_builder_t< Result >::option_builder_t ( char short_name,
std::string_view long_name )
inline

Constructs a builder with both short and long names.

Parameters
short_nameShort name (without "-").
long_nameLong name (without "--").

◆ option_builder_t() [2/3]

template<extends_result Result = result_base_t>
koutil::args::option_builder_t< Result >::option_builder_t ( char short_name)
inline

Constructs a builder with only a short name.

Parameters
short_nameShort name (without "-").

◆ option_builder_t() [3/3]

template<extends_result Result = result_base_t>
koutil::args::option_builder_t< Result >::option_builder_t ( std::string_view long_name)
inline

Constructs a builder with only a long name.

Parameters
long_nameLong name (without "--").

Member Function Documentation

◆ build() [1/2]

template<extends_result Result = result_base_t>
option_t koutil::args::option_builder_t< Result >::build ( ) &&
inline

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>
option_t koutil::args::option_builder_t< Result >::build ( Handle && handle) &&
inline

Builds the option with an explicit handler.

Template Parameters
HandleCallable type compatible with void(std::optional<std::string_view>, result_t&).
Parameters
handleFunction to handle the option’s value.
Returns
Constructed option.

◆ description()

template<extends_result Result = result_base_t>
option_builder_t && koutil::args::option_builder_t< Result >::description ( std::string_view description) &&
inline

Sets the option description.

Parameters
descriptionDescription text.
Returns
Builder.

◆ handle()

template<extends_result Result = result_base_t>
template<void_handle< std::optional< std::string_view >, result_t & > Handle>
option_builder_t && koutil::args::option_builder_t< Result >::handle ( Handle && handle) &&
inline

Assigns a handler function to the option.

Template Parameters
HandleCallable type compatible with void(std::optional<std::string_view>, result_t&).
Parameters
handleFunction to handle the option’s value.
Returns
Builder.

◆ has_value()

template<extends_result Result = result_base_t>
option_builder_t && koutil::args::option_builder_t< Result >::has_value ( bool value = true) &&
inline

Marks the option as one that expects a value.

Parameters
valueTrue if it has a value.
Returns
Builder.

◆ required()

template<extends_result Result = result_base_t>
option_builder_t && koutil::args::option_builder_t< Result >::required ( bool required = true) &&
inline

Marks the option as required.

Parameters
requiredTrue if required.
Returns
Builder.

Member Data Documentation

◆ m_data

template<extends_result Result = result_base_t>
option_data_t koutil::args::option_builder_t< Result >::m_data
private

◆ m_handle

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

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