kaycxx-cli
C++ CLI library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
kaycxx::cli::option< T > Class Template Reference

Typed command line option definition. More...

#include <kaycxx/cli/option.hpp>

Inheritance diagram for kaycxx::cli::option< T >:
Inheritance graph
[legend]
Collaboration diagram for kaycxx::cli::option< T >:
Collaboration graph
[legend]

Public Member Functions

 option (std::string_view name, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Creates an option without a short alias.
 
 option (std::string_view name, char alias, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Creates an option with a short alias.
 
std::string constvalue_name () const noexcept override
 Returns the value placeholder name.
 
void default_value (T value)
 Sets the default option value.
 
std::string usage () const override
 Returns generated help usage for this option.
 
bool expects_value () const noexcept override
 Checks whether this option expects a value.
 
std::optional< std::any > default_value () const override
 Returns the configured default value.
 
- Public Member Functions inherited from kaycxx::cli::option_base
bool is_repeatable () const noexcept
 Checks whether this option accepts multiple occurrences.
 
 switch_base (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Creates a switch without a short alias.
 
 switch_base (std::string_view name, char alias, std::optional< std::string_view > description=std::nullopt)
 Creates a switch with a short alias.
 
- Public Member Functions inherited from kaycxx::cli::switch_base
 switch_base (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Creates a switch without a short alias.
 
 switch_base (std::string_view name, char alias, std::optional< std::string_view > description=std::nullopt)
 Creates a switch with a short alias.
 
virtual ~switch_base ()=default
 Destroys the switch definition.
 
std::string constname () const noexcept
 Returns the long switch name.
 
std::optional< charalias () const noexcept
 Returns the short switch alias.
 
std::optional< std::string > constdescription () const noexcept
 Returns the switch description.
 
void mark_as_action () noexcept
 Marks this switch as a mutually exclusive command action.
 
bool is_action () const noexcept
 Checks whether this switch is a command action.
 

Detailed Description

template<parseable_value T>
class kaycxx::cli::option< T >

Typed command line option definition.

Template Parameters
TParsed option value type.

Constructor & Destructor Documentation

◆ option() [1/2]

template<parseable_value T>
kaycxx::cli::option< T >::option ( std::string_view  name,
std::string_view  value_name,
std::optional< std::string_view >  description = std::nullopt 
)
inlineexplicit

Creates an option without a short alias.

Parameters
nameLong option name without the leading --.
value_namePlaceholder name for the option value used by generated help output.
descriptionOptional human-readable option description used by generated help output.

◆ option() [2/2]

template<parseable_value T>
kaycxx::cli::option< T >::option ( std::string_view  name,
char  alias,
std::string_view  value_name,
std::optional< std::string_view >  description = std::nullopt 
)
inlineexplicit

Creates an option with a short alias.

Parameters
nameLong option name without the leading --.
aliasShort option alias without the leading -.
value_namePlaceholder name for the option value used by generated help output.
descriptionOptional human-readable option description used by generated help output.

Member Function Documentation

◆ default_value() [1/2]

template<parseable_value T>
std::optional< std::any > kaycxx::cli::option< T >::default_value ( ) const
inlineoverridevirtual

Returns the configured default value.

Returns
Default value stored in type-erased form or an empty optional if no default value is configured.

Implements kaycxx::cli::option_base.

◆ default_value() [2/2]

template<parseable_value T>
void kaycxx::cli::option< T >::default_value ( T  value)
inline

Sets the default option value.

Parameters
valueDefault value used when the option is not present in parsed arguments.

◆ expects_value()

template<parseable_value T>
bool kaycxx::cli::option< T >::expects_value ( ) const
inlineoverridevirtualnoexcept

Checks whether this option expects a value.

Returns
Always true.

Implements kaycxx::cli::switch_base.

◆ usage()

template<parseable_value T>
std::string kaycxx::cli::option< T >::usage ( ) const
inlineoverridevirtual

Returns generated help usage for this option.

Returns
Usage text.

Implements kaycxx::cli::switch_base.

◆ value_name()

template<parseable_value T>
std::string const & kaycxx::cli::option< T >::value_name ( ) const
inlineoverridevirtualnoexcept

Returns the value placeholder name.

Returns
Placeholder name used by generated help output and parse errors.

Implements kaycxx::cli::option_base.


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