My Project
Classes | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
uuid::console::Commands Class Reference

Container of commands for use by a Shell. More...

#include <uuid/console.h>

Collaboration diagram for uuid::console::Commands:
Collaboration graph
[legend]

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 > &current_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, Commandcommands_
 

Detailed Description

Container of commands for use by a Shell.

These should normally be stored in a std::shared_ptr and reused.

Since
0.1.0

Definition at line 90 of file console.h.

Member Typedef Documentation

◆ argument_completion_function

using uuid::console::Commands::argument_completion_function = std::function<const std::vector<std::string>( Shell &shell, const std::vector<std::string> &current_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.

Parameters
[in]shellShell instance that has a command line matching this command.
[in]current_argumentsCommand line arguments prior to (but excluding) the argument being completed.
[in]next_argumentNext argument (the one being completed).
Returns
Possible values for the next argument on the command line.
Since
2.0.0

Definition at line 132 of file console.h.

◆ command_function

using uuid::console::Commands::command_function = std::function<void(Shell &shell, std::vector<std::string> &arguments)>

Function to handle a command.

Parameters
[in]shellShell instance that is executing the command.
[in]argumentsCommand line arguments.
Since
0.1.0

Definition at line 113 of file console.h.

Constructor & Destructor Documentation

◆ Commands()

uuid::console::Commands::Commands ( )
default

Construct a new container of commands for use by a Shell.

This should normally be stored in a std::shared_ptr and reused.

Since
0.1.0

Member Function Documentation

◆ add_command() [1/12]

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.

Parameters
[in]nameName of the command as a std::vector of flash strings.
[in]functionFunction to be used when the command is executed.
Since
0.2.0

Definition at line 46 of file commands.cpp.

◆ add_command() [2/12]

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.

Parameters
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
Since
0.2.0

Definition at line 50 of file commands.cpp.

◆ add_command() [3/12]

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.

Parameters
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
[in]arg_functionFunction to be used to perform argument completions for this command.
Since
0.2.0

Definition at line 55 of file commands.cpp.

◆ add_command() [4/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]nameName of the command as a std::vector of flash strings.
[in]functionFunction to be used when the command is executed.
Since
0.8.0

Definition at line 60 of file commands.cpp.

◆ add_command() [5/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
Since
0.8.0

Definition at line 65 of file commands.cpp.

◆ add_command() [6/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
[in]arg_functionFunction to be used to perform argument completions for this command.
Since
0.8.0

Definition at line 70 of file commands.cpp.

◆ add_command() [7/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]functionFunction to be used when the command is executed.
Since
0.1.0

Definition at line 76 of file commands.cpp.

◆ add_command() [8/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
Since
0.1.0

Definition at line 81 of file commands.cpp.

◆ add_command() [9/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
[in]arg_functionFunction to be used to perform argument completions for this command.
Since
0.1.0

Definition at line 87 of file commands.cpp.

◆ add_command() [10/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]not_flagsShell flags that must not be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]functionFunction to be used when the command is executed.
Since
0.8.0

Definition at line 93 of file commands.cpp.

◆ add_command() [11/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]not_flagsShell flags that must not be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
Since
0.8.0

Definition at line 98 of file commands.cpp.

◆ add_command() [12/12]

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.

Parameters
[in]contextShell context in which this command is available.
[in]flagsShell flags that must be set for this command to be available.
[in]not_flagsShell flags that must not be set for this command to be available.
[in]nameName of the command as a std::vector of flash strings.
[in]argumentsHelp text for arguments that the command accepts as a std::vector of flash strings (use "<" to indicate a required argument).
[in]functionFunction to be used when the command is executed.
[in]arg_functionFunction to be used to perform argument completions for this command.
Since
0.8.0

Definition at line 104 of file commands.cpp.

◆ available_commands()

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.

Parameters
[in]shellShell that is accessing commands.
Returns
An iterable object describing the available commands.
Since
0.9.0

Definition at line 28 of file commands_iterable.cpp.

◆ complete_command()

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.

Parameters
[in]shellShell that is completing the command.
[in]command_lineCommand line parameters.
Returns
An object describing the result of the command completion operation.
Since
0.1.0

Definition at line 230 of file commands.cpp.

◆ execute_command()

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.

Parameters
[in]shellShell that is executing the command.
[in]command_lineCommand line parameters.
Returns
An object describing the result of the command execution operation.
Since
0.1.0

Definition at line 111 of file commands.cpp.

◆ find_command()

Commands::Match uuid::console::Commands::find_command ( Shell shell,
const CommandLine command_line 
)
private

Find commands by matching them against the command line.

Parameters
[in]shellShell that is accessing commands.
[in]command_lineCommand line parameters.
Returns
An object describing the result of the command find operation.
Since
0.1.0

Definition at line 456 of file commands.cpp.

◆ find_longest_common_prefix() [1/2]

bool uuid::console::Commands::find_longest_common_prefix ( const std::multimap< size_t, const Command * > &  commands,
std::vector< std::string > &  longest_name 
)
staticprivate

Find the longest common prefix from a shortest match of commands.

Parameters
[in]commandsAll commands that matched (at least 2).
[out]longest_nameThe longest common prefix as a list of strings.
Returns
True if the longest common prefix is made up of whole components, false if the last part is constructed from a partial component.
Since
0.1.0

Definition at line 145 of file commands.cpp.

◆ find_longest_common_prefix() [2/2]

std::string uuid::console::Commands::find_longest_common_prefix ( const std::vector< std::string > &  arguments)
staticprivate

Find the longest common prefix from a list of potential arguments.

Parameters
[in]argumentsAll potential arguments (at least 2).
Returns
The longest common prefix, which could be empty.
Since
0.1.0

Definition at line 207 of file commands.cpp.

Member Data Documentation

◆ commands_

std::multimap<unsigned int,Command> uuid::console::Commands::commands_
private

Commands stored in this container, separated by context.

Since
0.1.0

Definition at line 762 of file console.h.


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