My Project
|
Container of commands for use by a Shell. More...
#include <uuid/console.h>
Classes | |
class | AvailableCommand |
Available command for execution on a Shell. More... | |
class | AvailableCommands |
Available commands in the shell's context with the current flags. More... | |
class | Command |
Command for execution on a Shell. More... | |
struct | Completion |
Result of a command completion operation. More... | |
struct | Execution |
Result of a command execution operation. More... | |
struct | Match |
Result of a command find operation. More... | |
Public Types | |
using | command_function = std::function< void(Shell &shell, std::vector< std::string > &arguments)> |
Function to handle a command. More... | |
using | argument_completion_function = std::function< const std::vector< std::string >(Shell &shell, const std::vector< std::string > ¤t_arguments, const std::string &next_argument)> |
Function to obtain completions for a command line. More... | |
Public Member Functions | |
Commands ()=default | |
Construct a new container of commands for use by a Shell. More... | |
void | add_command (const flash_string_vector &name, command_function function) |
Add a command with no arguments to the list of commands in this container. More... | |
void | add_command (const flash_string_vector &name, const flash_string_vector &arguments, command_function function) |
Add a command with arguments to the list of commands in this container. More... | |
void | add_command (const flash_string_vector &name, const flash_string_vector &arguments, command_function function, argument_completion_function arg_function) |
Add a command with arguments and automatic argument completion to the list of commands in this container. More... | |
void | add_command (unsigned int context, const flash_string_vector &name, command_function function) |
Add a command with no arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, const flash_string_vector &name, const flash_string_vector &arguments, command_function function) |
Add a command with arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, const flash_string_vector &name, const flash_string_vector &arguments, command_function function, argument_completion_function arg_function) |
Add a command with arguments and automatic argument completion to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, const flash_string_vector &name, command_function function) |
Add a command with no arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, const flash_string_vector &name, const flash_string_vector &arguments, command_function function) |
Add a command with arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, const flash_string_vector &name, const flash_string_vector &arguments, command_function function, argument_completion_function arg_function) |
Add a command with arguments and automatic argument completion to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, unsigned int not_flags, const flash_string_vector &name, command_function function) |
Add a command with no arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, unsigned int not_flags, const flash_string_vector &name, const flash_string_vector &arguments, command_function function) |
Add a command with arguments to the list of commands in this container. More... | |
void | add_command (unsigned int context, unsigned int flags, unsigned int not_flags, const flash_string_vector &name, const flash_string_vector &arguments, command_function function, argument_completion_function arg_function) |
Add a command with arguments and automatic argument completion to the list of commands in this container. More... | |
Execution | execute_command (Shell &shell, CommandLine &&command_line) |
Execute a command for a Shell if it exists in the current context and with the current flags. More... | |
Completion | complete_command (Shell &shell, const CommandLine &command_line) |
Complete a partial command for a Shell if it exists in the current context and with the current flags. More... | |
AvailableCommands | available_commands (const Shell &shell) const |
Get the available commands in the current context and with the current flags. More... | |
Private Member Functions | |
Match | find_command (Shell &shell, const CommandLine &command_line) |
Find commands by matching them against the command line. More... | |
Static Private Member Functions | |
static bool | find_longest_common_prefix (const std::multimap< size_t, const Command * > &commands, std::vector< std::string > &longest_name) |
Find the longest common prefix from a shortest match of commands. More... | |
static std::string | find_longest_common_prefix (const std::vector< std::string > &arguments) |
Find the longest common prefix from a list of potential arguments. More... | |
Private Attributes | |
std::multimap< unsigned int, Command > | commands_ |
Container of commands for use by a Shell.
These should normally be stored in a std::shared_ptr and reused.
using uuid::console::Commands::argument_completion_function = std::function<const std::vector<std::string>( Shell &shell, const std::vector<std::string> ¤t_arguments, const std::string &next_argument)> |
Function to obtain completions for a command line.
This is a vector instead of set so that a custom sort order can be used. It should normally be sorted lexicographically so that the list of options is not confusing.
[in] | shell | Shell instance that has a command line matching this command. |
[in] | current_arguments | Command line arguments prior to (but excluding) the argument being completed. |
[in] | next_argument | Next argument (the one being completed). |
using uuid::console::Commands::command_function = std::function<void(Shell &shell, std::vector<std::string> &arguments)> |
|
default |
Construct a new container of commands for use by a Shell.
This should normally be stored in a std::shared_ptr and reused.
void uuid::console::Commands::add_command | ( | const flash_string_vector & | name, |
command_function | function | ||
) |
Add a command with no arguments to the list of commands in this container.
The shell context for the command will default to 0 and not require any flags for it to be available.
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | function | Function to be used when the command is executed. |
Definition at line 46 of file commands.cpp.
void uuid::console::Commands::add_command | ( | const flash_string_vector & | name, |
const flash_string_vector & | arguments, | ||
command_function | function | ||
) |
Add a command with arguments to the list of commands in this container.
The shell context for the command will default to 0 and not require any flags for it to be available.
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
Definition at line 50 of file commands.cpp.
void uuid::console::Commands::add_command | ( | const flash_string_vector & | name, |
const flash_string_vector & | arguments, | ||
command_function | function, | ||
argument_completion_function | arg_function | ||
) |
Add a command with arguments and automatic argument completion to the list of commands in this container.
The shell context for the command will default to 0 and not require any flags for it to be available.
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
[in] | arg_function | Function to be used to perform argument completions for this command. |
Definition at line 55 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
const flash_string_vector & | name, | ||
command_function | function | ||
) |
Add a command with no arguments to the list of commands in this container.
The command will not require any flags for it to be available.
[in] | context | Shell context in which this command is available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | function | Function to be used when the command is executed. |
Definition at line 60 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function | ||
) |
Add a command with arguments to the list of commands in this container.
The command will not require any flags for it to be available.
[in] | context | Shell context in which this command is available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
Definition at line 65 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function, | ||
argument_completion_function | arg_function | ||
) |
Add a command with arguments and automatic argument completion to the list of commands in this container.
The command will not require any flags for it to be available.
[in] | context | Shell context in which this command is available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
[in] | arg_function | Function to be used to perform argument completions for this command. |
Definition at line 70 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
const flash_string_vector & | name, | ||
command_function | function | ||
) |
Add a command with no arguments to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | function | Function to be used when the command is executed. |
Definition at line 76 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function | ||
) |
Add a command with arguments to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
Definition at line 81 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function, | ||
argument_completion_function | arg_function | ||
) |
Add a command with arguments and automatic argument completion to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
[in] | arg_function | Function to be used to perform argument completions for this command. |
Definition at line 87 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
unsigned int | not_flags, | ||
const flash_string_vector & | name, | ||
command_function | function | ||
) |
Add a command with no arguments to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | not_flags | Shell flags that must not be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | function | Function to be used when the command is executed. |
Definition at line 93 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
unsigned int | not_flags, | ||
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function | ||
) |
Add a command with arguments to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | not_flags | Shell flags that must not be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
Definition at line 98 of file commands.cpp.
void uuid::console::Commands::add_command | ( | unsigned int | context, |
unsigned int | flags, | ||
unsigned int | not_flags, | ||
const flash_string_vector & | name, | ||
const flash_string_vector & | arguments, | ||
command_function | function, | ||
argument_completion_function | arg_function | ||
) |
Add a command with arguments and automatic argument completion to the list of commands in this container.
[in] | context | Shell context in which this command is available. |
[in] | flags | Shell flags that must be set for this command to be available. |
[in] | not_flags | Shell flags that must not be set for this command to be available. |
[in] | name | Name of the command as a std::vector of flash strings. |
[in] | arguments | Help text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument). |
[in] | function | Function to be used when the command is executed. |
[in] | arg_function | Function to be used to perform argument completions for this command. |
Definition at line 104 of file commands.cpp.
Commands::AvailableCommands uuid::console::Commands::available_commands | ( | const Shell & | shell | ) | const |
Get the available commands in the current context and with the current flags.
This iterable object and its iterators are invalidated if the commands, context or flags for the shell change.
[in] | shell | Shell that is accessing commands. |
Definition at line 28 of file commands_iterable.cpp.
Commands::Completion uuid::console::Commands::complete_command | ( | Shell & | shell, |
const CommandLine & | command_line | ||
) |
Complete a partial command for a Shell if it exists in the current context and with the current flags.
Definition at line 230 of file commands.cpp.
Commands::Execution uuid::console::Commands::execute_command | ( | Shell & | shell, |
CommandLine && | command_line | ||
) |
Execute a command for a Shell if it exists in the current context and with the current flags.
Definition at line 111 of file commands.cpp.
|
private |
Find commands by matching them against the command line.
Definition at line 456 of file commands.cpp.
|
staticprivate |
Find the longest common prefix from a shortest match of commands.
[in] | commands | All commands that matched (at least 2). |
[out] | longest_name | The longest common prefix as a list of strings. |
Definition at line 145 of file commands.cpp.
|
staticprivate |
Find the longest common prefix from a list of potential arguments.
[in] | arguments | All potential arguments (at least 2). |
Definition at line 207 of file commands.cpp.
|
private |