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

Typed single positional parameter definition. More...

#include <kaycxx/cli/parameter.hpp>

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

Public Member Functions

 parameter (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Creates a positional parameter definition.
 
void default_value (T value)
 Sets the default parameter value.
 
std::string usage () const override
 Returns generated help usage for this parameter.
 
std::size_t min_count () const noexcept override
 Returns the minimum number of values consumed by this parameter.
 
std::size_t max_count () const noexcept override
 Returns the maximum number of values consumed by this parameter.
 
std::any parse_values (std::span< std::string_view const > values) const override
 Parses this positional parameter.
 
- Public Member Functions inherited from kaycxx::cli::parameter_base
 parameter_base (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Creates a positional parameter definition.
 
virtual ~parameter_base ()=default
 Destroys the parameter definition.
 
std::string constname () const noexcept
 Returns the parameter name.
 
std::optional< std::string > constdescription () const noexcept
 Returns the parameter description.
 

Detailed Description

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

Typed single positional parameter definition.

Template Parameters
TParsed parameter value type.

Constructor & Destructor Documentation

◆ parameter()

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

Creates a positional parameter definition.

Parameters
namePlaceholder name used by generated help output and parse errors.
descriptionOptional human-readable parameter description used by generated help output.

Member Function Documentation

◆ default_value()

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

Sets the default parameter value.

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

◆ max_count()

template<parseable_value T>
std::size_t kaycxx::cli::parameter< T >::max_count ( ) const
inlineoverridevirtualnoexcept

Returns the maximum number of values consumed by this parameter.

Returns
Always one.

Implements kaycxx::cli::parameter_base.

◆ min_count()

template<parseable_value T>
std::size_t kaycxx::cli::parameter< T >::min_count ( ) const
inlineoverridevirtualnoexcept

Returns the minimum number of values consumed by this parameter.

Returns
Zero when a default value is configured, otherwise one.

Implements kaycxx::cli::parameter_base.

◆ parse_values()

template<parseable_value T>
std::any kaycxx::cli::parameter< T >::parse_values ( std::span< std::string_view const values) const
inlineoverridevirtual

Parses this positional parameter.

Parameters
valuesValue texts to parse.
Returns
Parsed parameter value stored in type-erased form.
Exceptions
parse_errorWhen the value is syntactically invalid or no value is present and no default value is configured.

Implements kaycxx::cli::parameter_base.

◆ usage()

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

Returns generated help usage for this parameter.

Returns
Usage text.

Implements kaycxx::cli::parameter_base.


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