Ookii.CommandLine for C++
1.0.0
|
Manages registration, creation and invocation of shell commands for an application. More...
#include <ookii/shell_command.h>
Public Types | |
using | builder_type = typename info_type::builder_type |
The concrete type of basic_parser_builder used. | |
using | command_type = typename info_type::command_type |
The concrete type of basic_shell_command used. | |
using | info_type = shell_command_info< CharType, Traits, Alloc > |
The concrete type of shell_command_info used. | |
using | stream_type = std::basic_ostream< CharType, Traits > |
The concrete type of output stream used. | |
using | string_type = typename info_type::string_type |
The concrete string type used. | |
using | usage_options_type = basic_shell_command_usage_options< CharType, Traits, Alloc > |
The concrete type of basic_shell_command_usage_options used. | |
Public Member Functions | |
basic_shell_command_manager (string_type application_name, bool case_sensitive=false, const std::locale &locale={}) | |
Initializes a new instance of the basic_shell_command_manager class. More... | |
template<typename T > | |
basic_shell_command_manager & | add_command (string_type name={}, string_type description={}) |
Adds a command to the basic_shell_command_manager. More... | |
auto | commands () const noexcept |
Gets a view of all the commands. More... | |
template<typename Iterator > | |
std::unique_ptr< command_type > | create_command (const string_type &name, Iterator begin, Iterator end, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments. More... | |
template<typename Range > | |
std::unique_ptr< command_type > | create_command (const string_type &name, Range range, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments. More... | |
template<typename T > | |
std::unique_ptr< command_type > | create_command (const string_type &name, std::initializer_list< T > args, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments. More... | |
std::unique_ptr< command_type > | create_command (int argc, const CharType *const argv[], const usage_options_type &options={}) const |
Creates an instance of a command based on the specified arguments. More... | |
template<typename Iterator > | |
std::unique_ptr< command_type > | create_command (Iterator begin, Iterator end, const usage_options_type &options={}) const |
Creates an instance of a command based on the specified arguments. More... | |
template<typename Range > | |
std::unique_ptr< command_type > | create_command (Range range, const usage_options_type &options={}) const |
Creates an instance of a command based on the specified arguments. More... | |
template<typename T > | |
std::unique_ptr< command_type > | create_command (std::initializer_list< T > args, const usage_options_type &options={}) const |
Creates an instance of a command based on the specified arguments. More... | |
builder_type | create_parser_builder (const info_type &command) const |
Creates a basic_parser_builder for a specified command. More... | |
const info_type * | get_command (const string_type &name) const |
Gets information about a shell command by name. More... | |
template<typename Iterator > | |
int | run_command (const string_type &name, Iterator begin, Iterator end, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments, and runs the command. More... | |
template<typename Range > | |
int | run_command (const string_type &name, Range range, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments, and runs the command. More... | |
template<typename T > | |
int | run_command (const string_type &name, std::initializer_list< T > args, const usage_options_type &options={}) const |
Creates an instance of the specified command, parsing the specified arguments, and runs the command. More... | |
int | run_command (int argc, const CharType *const argv[], const usage_options_type &options={}) const |
Creates an instance of a command based onthe specified arguments, and runs the command. More... | |
template<typename Iterator > | |
int | run_command (Iterator begin, Iterator end, const usage_options_type &options={}) const |
Creates an instance of a command based onthe specified arguments, and runs the command. More... | |
template<typename Range > | |
int | run_command (Range range, const usage_options_type &options={}) const |
Creates an instance of a command based onthe specified arguments, and runs the command. More... | |
template<typename T > | |
int | run_command (std::initializer_list< T > args, const usage_options_type &options={}) const |
Creates an instance of a command based onthe specified arguments, and runs the command. More... | |
void | write_usage (const usage_options_type &options={}) const |
Writes usage help about the available commands. More... | |
Static Public Attributes | |
static constexpr int | error_return_code = 1 |
The error exit code used by run_shell_command() if no command name was supplied or thesupplied command could not be found. | |
Manages registration, creation and invocation of shell commands for an application.
To use shell commands in your application, you define a class that derives from basic_shell_command for each one. Then, you register each class with the basic_shell_command_manager using the add_command() method.
You can then invoke create_command() to create an instance of a command type based on the provided arguments, or run_command() to create a command and immediately run it.
Several typedefs for common character types are provided:
Type | Definition |
---|---|
ookii::shell_command_manager | ookii::basic_shell_command_manager<char> |
ookii::wshell_command_manager | ookii::basic_shell_command_manager<wchar_t> |
CharType | The character type used for arguments and other strings. Only char and wchar_t are supported. Defaults to wchar_t if _UNICODE is defined, otherwise to char . |
Traits | The character traits to use for strings. Defaults to std::char_traits<CharType> . |
Alloc | The allocator to use for strings. Defaults to std::allocator<CharType> . |
|
inline |
Initializes a new instance of the basic_shell_command_manager class.
application_name | The name of the application containing the command. This name is used when printing usage help. |
case_sensitive | Indicates whether command names and argument names are case sensitive. The default is false. |
locale | The locale to use when converting argument values. The default is a copy of the current global locale. |
|
inline |
Adds a command to the basic_shell_command_manager.
The | type of the command, which must derive from basic_shell_command<CharType>. |
name | The name used to invoke the command. If left blank, it will be determined by the static name() method of the command type, or the type name if there is no such method. |
description | The description of the command, used for usage help. If left blank, it will be determined by the static description() method of the command type. If no such method exist, the description will be blank. |
|
inlinenoexcept |
Gets a view of all the commands.
|
inline |
Creates an instance of the specified command, parsing the specified arguments.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Iterator | The type of iterator for the arguments. |
name | The name of the shell command. |
begin | An iterator to the first argument. |
end | An iterator after the last argument. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of the specified command, parsing the specified arguments.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Range | The type of a range containing the arguments. |
name | The name of the shell command. |
range | A range containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of the specified command, parsing the specified arguments.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
T | The type of the elements in the initializer list. This must be a string type that can be converted to std::basic_string<CharType, Traits, Alloc>. |
name | The name of the shell command. |
args | An initializer list containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of a command based on the specified arguments.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
argc | The number of arguments. |
argv | The arguments.. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of a command based on the specified arguments.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Iterator | The type of iterator for the arguments. |
begin | An iterator to the first argument. |
end | An iterator after the last argument. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of a command based on the specified arguments.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Range | The type of a range containing the arguments. |
range | A range containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates an instance of a command based on the specified arguments.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
T | The type of the elements in the initializer list. This must be a string type that can be converted to std::basic_string<CharType, Traits, Alloc>. |
args | An initializer list containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
nullptr
if the an error occurred.
|
inline |
Creates a basic_parser_builder for a specified command.
The parser builder will be initialized with the name and description of the command, as well the locale and case sensitive value of the basic_shell_command_manager.
command | The shell_command_info for the command. |
|
inline |
Gets information about a shell command by name.
name | The name of the shell command. |
nullptr
if there is no command with that name.
|
inline |
Creates an instance of the specified command, parsing the specified arguments, and runs the command.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Iterator | The type of iterator for the arguments. |
name | The name of the shell command. |
begin | An iterator to the first argument. |
end | An iterator after the last argument. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of the specified command, parsing the specified arguments, and runs the command.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Range | The type of a range containing the arguments. |
name | The name of the shell command. |
range | A range containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of the specified command, parsing the specified arguments, and runs the command.
If the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
T | The type of the elements in the initializer list. This must be a string type that can be converted to std::basic_string<CharType, Traits, Alloc>. |
name | The name of the shell command. |
args | An initializer list containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of a command based onthe specified arguments, and runs the command.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
argc | The number of arguments. |
argv | The arguments.. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of a command based onthe specified arguments, and runs the command.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Iterator | The type of iterator for the arguments. |
begin | An iterator to the first argument. |
end | An iterator after the last argument. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of a command based onthe specified arguments, and runs the command.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
Range | The type of a range containing the arguments. |
range | A range containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Creates an instance of a command based onthe specified arguments, and runs the command.
If no command was specified or the command could not be found, a list of commands will be written. If an error occurred parsing the arguments, an error message and usage help for the command will be written.
T | The type of the elements in the initializer list. This must be a string type that can be converted to std::basic_string<CharType, Traits, Alloc>. |
args | An initializer list containing the arguments. |
options | A basic_shell_command_usage_options instance that will be used to format errors and usage help. |
|
inline |
Writes usage help about the available commands.
options | A basic_shell_command_usage_options instance that will be used to format the usage help. |