kaycxx-cli
C++ CLI library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
kaycxx::cli::switch_base Class Referenceabstract

Common base class for command line switches. More...

#include <kaycxx/cli/switch_base.hpp>

Inheritance diagram for kaycxx::cli::switch_base:
Inheritance graph
[legend]

Public Member Functions

 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.
 
virtual std::string usage () const =0
 Returns generated help usage for this switch.
 
virtual bool expects_value () const noexcept=0
 Checks whether this switch expects a value.
 

Detailed Description

Common base class for command line switches.

A switch is either a flag without a value or an option with a value.

Constructor & Destructor Documentation

◆ switch_base() [1/2]

kaycxx::cli::switch_base::switch_base ( std::string_view  name,
std::optional< std::string_view >  description = std::nullopt 
)
explicit

Creates a switch without a short alias.

Parameters
nameLong switch name without the leading --.
descriptionOptional human-readable description used by generated help output.

◆ switch_base() [2/2]

kaycxx::cli::switch_base::switch_base ( std::string_view  name,
char  alias,
std::optional< std::string_view >  description = std::nullopt 
)
explicit

Creates a switch with a short alias.

Parameters
nameLong switch name without the leading --.
aliasShort switch alias without the leading -.
descriptionOptional human-readable description used by generated help output.

Member Function Documentation

◆ alias()

std::optional< char > kaycxx::cli::switch_base::alias ( ) const
noexcept

Returns the short switch alias.

Returns
Short alias without the leading - or an empty optional if no alias is configured.

◆ description()

std::optional< std::string > const & kaycxx::cli::switch_base::description ( ) const
noexcept

Returns the switch description.

Returns
Human-readable description or an empty optional if no description was configured.

◆ expects_value()

virtual bool kaycxx::cli::switch_base::expects_value ( ) const
pure virtualnoexcept

Checks whether this switch expects a value.

Returns
True for options, false for flags.

Implemented in kaycxx::cli::flag, and kaycxx::cli::option< T >.

◆ is_action()

bool kaycxx::cli::switch_base::is_action ( ) const
noexcept

Checks whether this switch is a command action.

Returns
True when the switch is an action, false otherwise.

◆ name()

std::string const & kaycxx::cli::switch_base::name ( ) const
noexcept

Returns the long switch name.

Returns
Long switch name without the leading --.

◆ usage()

virtual std::string kaycxx::cli::switch_base::usage ( ) const
pure virtual

Returns generated help usage for this switch.

Returns
Usage text.

Implemented in kaycxx::cli::flag, and kaycxx::cli::option< T >.


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