|
ChainCLI
A modern C++20 command-line interface library
|
Represents a command in the CLI application. More...
#include <command.h>
Public Member Functions | |
| Command (std::string_view id, std::string_view short_desc, std::string_view long_desc, std::unique_ptr< std::function< void(const CliContext &)> > actionPtr) | |
| Construct a new Command object. | |
| Command (std::string_view id, std::string_view short_desc, std::string_view long_desc, std::function< void(const CliContext &)> action) | |
| Construct a new Command object. | |
| Command (std::string_view id) | |
| Construct a new Command object. | |
| Command (Command &&) noexcept=default | |
| Command & | operator= (Command &&) noexcept=default |
| Command (const Command &)=delete | |
| Command & | operator= (const Command &)=delete |
| constexpr std::string_view | getIdentifier () const noexcept |
| Get the unique identifier for the command. | |
| constexpr std::string_view | getShortDescription () const noexcept |
| Get the short description of the command. | |
| constexpr std::string_view | getLongDescription () const noexcept |
| Get the long description of the command. | |
| bool | hasExecutionFunction () const noexcept |
| Check if the command has an execution function. | |
| const std::vector< std::shared_ptr< PositionalArgumentBase > > & | getPositionalArguments () const noexcept |
| Get the positional arguments for the command. | |
| const std::vector< std::shared_ptr< OptionArgumentBase > > & | getOptionArguments () const noexcept |
| Get the option arguments for the command. | |
| const std::vector< std::shared_ptr< FlagArgument > > & | getFlagArguments () const noexcept |
| Get the flag arguments for the command. | |
| const std::vector< std::unique_ptr< ArgumentGroup > > & | getArgumentGroups () const noexcept |
| Get the argument groups for the command. | |
| std::string_view | getDocStringShort () const |
| Get the short documentation string for the command. | |
| std::string_view | getDocStringLong () const |
| Get the long documentation string for the command. | |
| Command * | getSubCommand (std::string_view id) |
| Get a sub-command by its identifier. | |
| const Command * | getSubCommand (std::string_view id) const |
| Get a sub-command by its identifier. | |
| auto & | getSubCommands () |
| Get all sub-commands of the command. | |
| auto const & | getSubCommands () const |
| Get all sub-commands of the command. | |
| void | execute (const CliContext &context) const |
| Execute the command. | |
| Command & | withShortDescription (std::string_view desc) |
| Set the short description for the command. | |
| Command & | withLongDescription (std::string_view desc) |
| Set the long description for the command. | |
| template<typename T > | |
| Command & | withPositionalArgument (std::shared_ptr< PositionalArgument< T > > arg) |
| Add a positional argument to the command. | |
| template<typename T > | |
| Command & | withPositionalArgument (PositionalArgument< T > &&arg) |
| Add a positional argument to the command. | |
| template<typename T > | |
| Command & | withPositionalArgument (PositionalArgument< T > &arg) |
| Add a positional argument to the command. | |
| template<typename T > | |
| Command & | withOptionArgument (std::shared_ptr< OptionArgument< T > > arg) |
| Add an option argument to the command. | |
| template<typename T > | |
| Command & | withOptionArgument (OptionArgument< T > &&arg) |
| Add an option argument to the command. | |
| template<typename T > | |
| Command & | withOptionArgument (OptionArgument< T > &arg) |
| Add an option argument to the command. | |
| Command & | withFlagArgument (std::shared_ptr< FlagArgument > arg) |
| Add a flag argument to the command. | |
| Command & | withFlagArgument (FlagArgument &&arg) |
| Add a flag argument to the command. | |
| Command & | withFlagArgument (FlagArgument &arg) |
| Add a flag argument to the command. | |
| Command & | withExecutionFunc (std::unique_ptr< std::function< void(const CliContext &)> > actionPtr) |
| Set the execution function for the command. | |
| Command & | withExecutionFunc (std::function< void(const CliContext &)> &&action) |
| Set the execution function for the command. | |
| Command & | withSubCommand (std::unique_ptr< Command > subCommandPtr) |
| Add a sub-command to this command. | |
| Command & | withSubCommand (Command &&subCommand) |
| template<typename... Args> requires ((sizeof...(Args) > 0) && (std::derived_from<std::remove_cvref_t<Args>, ArgumentBase> && ...)) | |
| Command & | withExclusiveGroup (Args &&...args) |
| Add a sub-command to this command. | |
| template<typename... Args> requires ((sizeof...(Args) > 0) && (std::derived_from<std::remove_cvref_t<Args>, ArgumentBase> && ...)) | |
| Command & | withInclusiveGroup (Args &&...args) |
| Add an inclusive argument group to this command. | |
Friends | |
| class | cli::commands::docwriting::DocWriter |
| std::ostream & | operator<< (std::ostream &out, const Command &cmd) |
Represents a command in the CLI application.
A command can have subcommands, arguments (positional, option, flag), and an execution function. Commands can be nested to create a hierarchy of commands and subcommands.
|
inline |
Construct a new Command object.
| id | The unique identifier for the command. |
| short_desc | A short description of the command. |
| long_desc | A long description of the command. |
| actionPtr | A pointer to the function to execute when the command is called. |
|
inline |
Construct a new Command object.
| id | The unique identifier for the command. |
| short_desc | A short description of the command. |
| long_desc | A long description of the command. |
| action | A function to execute when the command is called. |
|
inlineexplicit |
Construct a new Command object.
| id | The unique identifier for the command. |
| inline_t void cli::commands::Command::execute | ( | const CliContext & | context | ) | const |
Execute the command.
| context | The CLI context to use for execution. |
|
inlinenoexcept |
Get the argument groups for the command.
| inline_t std::string_view cli::commands::Command::getDocStringLong | ( | ) | const |
Get the long documentation string for the command.
This description contains the textual representation of the command and its arguments as well as the long description and the Options segment.
| inline_t std::string_view cli::commands::Command::getDocStringShort | ( | ) | const |
Get the short documentation string for the command.
This description only contains the textual representation of the command and its arguments as well as the short description.
|
inlinenoexcept |
Get the flag arguments for the command.
|
inlineconstexprnoexcept |
Get the unique identifier for the command.
|
inlineconstexprnoexcept |
Get the long description of the command.
|
inlinenoexcept |
Get the option arguments for the command.
|
inlinenoexcept |
Get the positional arguments for the command.
|
inlineconstexprnoexcept |
Get the short description of the command.
| inline_t Command * cli::commands::Command::getSubCommand | ( | std::string_view | id | ) |
Get a sub-command by its identifier.
| id | The identifier of the sub-command. |
| inline_t const Command * cli::commands::Command::getSubCommand | ( | std::string_view | id | ) | const |
Get a sub-command by its identifier.
| id | The identifier of the sub-command. |
|
inline |
Get all sub-commands of the command.
|
inline |
Get all sub-commands of the command.
|
inlinenoexcept |
Check if the command has an execution function.
|
inline |
Add a sub-command to this command.
| ...Args | The types of the sub-commands. |
| ...args | The sub-commands to add. |
| inline_t Command & cli::commands::Command::withExecutionFunc | ( | std::function< void(const CliContext &)> && | action | ) |
Set the execution function for the command.
| action | The function to execute when the command is called. |
| inline_t Command & cli::commands::Command::withExecutionFunc | ( | std::unique_ptr< std::function< void(const CliContext &)> > | actionPtr | ) |
Set the execution function for the command.
| action | The function to execute when the command is called. |
| inline_t Command & cli::commands::Command::withFlagArgument | ( | FlagArgument && | arg | ) |
Add a flag argument to the command.
| arg | The flag argument to set. |
| inline_t Command & cli::commands::Command::withFlagArgument | ( | FlagArgument & | arg | ) |
Add a flag argument to the command.
| arg | The flag argument to set. |
| inline_t Command & cli::commands::Command::withFlagArgument | ( | std::shared_ptr< FlagArgument > | arg | ) |
Add a flag argument to the command.
| arg | The flag argument to set. |
|
inline |
Add an inclusive argument group to this command.
| ...Args | The types of the sub-commands. |
| ...args | The sub-commands to add. |
| inline_t Command & cli::commands::Command::withLongDescription | ( | std::string_view | desc | ) |
Set the long description for the command.
| desc | The long description to set. |
|
inline |
Add an option argument to the command.
| T | The type of the option argument. |
| arg | The option argument to set. |
|
inline |
Add an option argument to the command.
| T | The type of the option argument. |
| arg | The option argument to set. |
|
inline |
Add an option argument to the command.
| T | The type of the option argument. |
| arg | The option argument to set. |
|
inline |
Add a positional argument to the command.
| T | The type of the positional argument. |
| arg | The positional argument to set. |
|
inline |
Add a positional argument to the command.
| T | The type of the positional argument. |
| arg | The positional argument to set. |
|
inline |
Add a positional argument to the command.
| T | The type of the positional argument. |
| arg | The positional argument to set. |
| inline_t Command & cli::commands::Command::withShortDescription | ( | std::string_view | desc | ) |
Set the short description for the command.
| desc | The short description to set. |
| inline_t Command & cli::commands::Command::withSubCommand | ( | std::unique_ptr< Command > | subCommandPtr | ) |
Add a sub-command to this command.
| subCommandPtr | The sub-command to add. |