|
kaycxx-cli
C++ CLI library
|
Defines and parses a command line interface. More...
#include <kaycxx/cli/command.hpp>
Public Member Functions | |
| command (std::string_view name, command_options options=command_options()) | |
| Creates a command definition. | |
| command (command const &)=delete | |
| Prevents copying command definitions. | |
| command & | operator= (command const &)=delete |
| Prevents copy-assigning command definitions. | |
| command (command &&other) noexcept=default | |
| Moves a command definition. | |
| command & | operator= (command &&other) noexcept=default |
| Move-assigns a command definition. | |
| std::string const & | name () const noexcept |
| Returns the command name. | |
| std::optional< std::string > const & | version () const noexcept |
| Returns the configured command version. | |
| std::optional< std::string > const & | author () const noexcept |
| Returns the configured author name. | |
| std::optional< std::string > const & | email () const noexcept |
| Returns the configured author email address. | |
| std::optional< std::string > const & | bugs () const noexcept |
| Returns the email address or URL to which to report bugs to. | |
| std::optional< std::string > const & | copyright () const noexcept |
| Returns the configured copyright notice. | |
| std::optional< std::string > const & | license () const noexcept |
| Returns the configured license text. | |
| std::optional< std::string > const & | description () const noexcept |
| Returns the configured command 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< T > | option (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< T > | option (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< T > | repeatable_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< T > | repeatable_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< T > | parameter (std::string_view name, std::optional< std::string_view > description=std::nullopt) |
| Registers a single positional parameter. | |
| template<parseable_value T> | |
| cli::parameters_handle< T > | parameters (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 () const |
| Writes generated help output to standard output. | |
| int | print_help (std::ostream &out) const |
| Writes generated help output. | |
| int | print_version () const |
| Writes generated version output to standard output. | |
| int | print_version (std::ostream &out) const |
| Writes generated version output. | |
Defines and parses a command line interface.
A command owns all registered flags, options and positional parameters. Registration methods return lightweight handles referencing these owned definitions.
The handles remain valid as long as the command object exists.
|
explicit |
Creates a command definition.
| name | Program name used in generated output and error messages. |
| options | Optional command metadata. |
|
defaultnoexcept |
Moves a command definition.
| other | Command definition to move from. |
|
noexcept |
Returns the configured author name.
|
noexcept |
Returns the email address or URL to which to report bugs to.
|
noexcept |
Returns the configured copyright notice.
|
noexcept |
Returns the configured command description.
|
noexcept |
Returns the configured author email address.
| cli::flag_handle kaycxx::cli::command::flag | ( | std::string_view | name, |
| char | alias, | ||
| std::optional< std::string_view > | description = std::nullopt |
||
| ) |
Registers a flag with a short alias.
| name | Long flag name without the leading --. |
| alias | Short flag alias without the leading -. |
| description | Optional human-readable flag description used by generated help output. |
| std::invalid_argument | When the long name or short alias is already registered. |
| cli::flag_handle kaycxx::cli::command::flag | ( | std::string_view | name, |
| std::optional< std::string_view > | description = std::nullopt |
||
| ) |
Registers a flag without a short alias.
| name | Long flag name without the leading --. |
| description | Optional human-readable flag description used by generated help output. |
| std::invalid_argument | When the long name is already registered. |
|
noexcept |
Returns the configured license text.
|
noexcept |
Returns the command name.
Move-assigns a command definition.
| other | Command definition to move from. |
|
inline |
Registers an option with a short alias.
| T | Parsed option value type. |
| name | Long option name without the leading --. |
| alias | Short option alias without the leading -. |
| value_name | Placeholder name for the option value used by generated help output. |
| description | Optional human-readable option description used by generated help output. |
| std::invalid_argument | When the long name or short alias is already registered. |
|
inline |
Registers an option without a short alias.
| T | Parsed option value type. |
| name | Long option name without the leading --. |
| value_name | Placeholder name for the option value used by generated help output. |
| description | Optional human-readable option description used by generated help output. |
| std::invalid_argument | When the long name is already registered. |
|
inline |
Registers a single positional parameter.
| T | Parsed parameter value type. |
| name | Placeholder name used by generated help output and parse errors. |
| description | Optional human-readable parameter description used by generated help output. |
|
inline |
Registers a positional parameter list.
| T | Parsed parameter value type. |
| name | Placeholder name used by generated help output and parse errors. |
| description | Optional human-readable parameter description used by generated help output. |
Parses command line arguments.
| argc | Argument count as received by main. |
| argv | Argument values as received by main. |
Positional arguments are stored without validation. They are validated and converted when first accessed through the returned argument collection or when args::validate() is called explicitly.
| parse_error | When a switch is unknown, an option value is missing or invalid, or multiple actions are specified. |
| int kaycxx::cli::command::print_help | ( | ) | const |
Writes generated help output to standard output.
main. | int kaycxx::cli::command::print_help | ( | std::ostream & | out | ) | const |
Writes generated help output.
| out | Output stream receiving the generated help text. |
main. | int kaycxx::cli::command::print_version | ( | ) | const |
Writes generated version output to standard output.
main. | int kaycxx::cli::command::print_version | ( | std::ostream & | out | ) | const |
Writes generated version output.
| out | Output stream receiving the generated version text. |
main.
|
inline |
Registers a repeatable option with a short alias.
| T | Parsed option value type. |
| name | Long option name without the leading --. |
| alias | Short option alias without the leading -. |
| value_name | Placeholder name for each option value used by generated help output. |
| description | Optional human-readable option description used by generated help output. |
| std::invalid_argument | When the long name or short alias is already registered. |
|
inline |
Registers a repeatable option without a short alias.
| T | Parsed option value type. |
| name | Long option name without the leading --. |
| value_name | Placeholder name for each option value used by generated help output. |
| description | Optional human-readable option description used by generated help output. |
| std::invalid_argument | When the long name is already registered. |
|
noexcept |
Returns the configured command version.