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

Defines and parses a command-line application. More...

#include <kaycxx/cli/app.hpp>

Inheritance diagram for kaycxx::cli::app:
Inheritance graph
[legend]
Collaboration diagram for kaycxx::cli::app:
Collaboration graph
[legend]

Public Member Functions

 app (std::string_view name, app_options options=app_options{})
 Creates a command-line application.
 
 app (app const &)=delete
 Prevents copying applications.
 
appoperator= (app const &)=delete
 Prevents copy-assigning applications.
 
 app (app &&other) noexcept
 Moves a command-line application.
 
 ~app () override=default
 Destroys the application and all definitions owned by it.
 
std::optional< std::string > constversion () const noexcept
 Returns the configured application version.
 
std::optional< std::string > constauthor () const noexcept
 Returns the configured author name.
 
std::optional< std::string > constemail () const noexcept
 Returns the configured author email address.
 
std::optional< std::string > constbugs () const noexcept
 Returns the configured bug-report destination.
 
std::optional< std::string > constcopyright () const noexcept
 Returns the configured copyright notice.
 
std::optional< std::string > constlicense () const noexcept
 Returns the configured license text.
 
command_handle command (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Registers a command.
 
- Public Member Functions inherited from kaycxx::cli::command
 command (command const &)=delete
 Prevents copying command definitions.
 
commandoperator= (command const &)=delete
 Prevents copy-assigning command definitions.
 
virtual ~command ()=default
 Destroys this command and all definitions owned by it.
 
std::string constname () const noexcept
 Returns the command name.
 
std::optional< std::string > constdescription () const noexcept
 Returns this command's configured description.
 
cli::flag_handle flag (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Registers a flag without a short alias.
 
cli::flag_handle flag (std::string_view name, char alias, std::optional< std::string_view > description=std::nullopt)
 Registers a flag with a short alias.
 
template<parseable_value T>
cli::option_handle< Toption (std::string_view name, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Registers an option without a short alias.
 
template<parseable_value T>
cli::option_handle< Toption (std::string_view name, char alias, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Registers an option with a short alias.
 
template<parseable_value T>
cli::repeatable_option_handle< Trepeatable_option (std::string_view name, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Registers a repeatable option without a short alias.
 
template<parseable_value T>
cli::repeatable_option_handle< Trepeatable_option (std::string_view name, char alias, std::string_view value_name, std::optional< std::string_view > description=std::nullopt)
 Registers a repeatable option with a short alias.
 
template<parseable_value T>
cli::parameter_handle< Tparameter (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Registers a single positional parameter.
 
template<parseable_value T>
cli::parameters_handle< Tparameters (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Registers a positional parameter list.
 
cli::args parse (int argc, char *argv[]) const
 Parses command line arguments.
 
int print_help (std::ostream &out=std::cout) const
 Writes generated help output.
 
int print_version (std::ostream &out=std::cout) const
 Writes generated version output.
 

Additional Inherited Members

- Protected Member Functions inherited from kaycxx::cli::command
 command (std::string_view name, std::optional< std::string_view > description, command *parent)
 Creates a command definition.
 
 command (command &&other) noexcept
 Moves a command definition.
 
command_handle add_command (std::string_view name, std::optional< std::string_view > description=std::nullopt)
 Registers a child command.
 

Detailed Description

Defines and parses a command-line application.

An application owns all registered flags, options, positional parameters and commands. Registration methods return lightweight handles to these owned definitions.

The handles remain valid as long as the application exists.

Constructor & Destructor Documentation

◆ app() [1/2]

kaycxx::cli::app::app ( std::string_view  name,
app_options  options = app_options{} 
)
explicit

Creates a command-line application.

Parameters
nameApplication name used in generated output and error messages.
optionsOptional application metadata.

◆ app() [2/2]

kaycxx::cli::app::app ( app &&  other)
noexcept

Moves a command-line application.

Parameters
otherApplication to move from.

Member Function Documentation

◆ author()

std::optional< std::string > const & kaycxx::cli::app::author ( ) const
noexcept

Returns the configured author name.

Returns
Author name or an empty optional if no author was configured.

◆ bugs()

std::optional< std::string > const & kaycxx::cli::app::bugs ( ) const
noexcept

Returns the configured bug-report destination.

Returns
Email address or URL to which to report bugs.

◆ command()

command_handle kaycxx::cli::app::command ( std::string_view  name,
std::optional< std::string_view >  description = std::nullopt 
)

Registers a command.

An application with commands cannot also define positional parameters. The returned handle remains valid while this application owns the command.

Parameters
nameCommand name.
descriptionOptional command description used by generated help output.
Returns
Handle for configuring and identifying the registered command.
Exceptions
std::invalid_argumentWhen the name is already registered or the application has positional parameters.

◆ copyright()

std::optional< std::string > const & kaycxx::cli::app::copyright ( ) const
noexcept

Returns the configured copyright notice.

Returns
Copyright notice or an empty optional if no copyright notice was configured.

◆ email()

std::optional< std::string > const & kaycxx::cli::app::email ( ) const
noexcept

Returns the configured author email address.

Returns
Email address or an empty optional if no email address was configured.

◆ license()

std::optional< std::string > const & kaycxx::cli::app::license ( ) const
noexcept

Returns the configured license text.

Returns
License text or an empty optional if no license text was configured.

◆ version()

std::optional< std::string > const & kaycxx::cli::app::version ( ) const
noexcept

Returns the configured application version.

Returns
Application version or an empty optional if no version was configured.

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