nfd::tools::nfdc::CommandParser Class Reference

Parses a command. More...

#include <tools/nfdc/command-parser.hpp>

+ Inheritance diagram for nfd::tools::nfdc::CommandParser:
+ Collaboration diagram for nfd::tools::nfdc::CommandParser:

Classes

class  NoSuchCommandError
 

Public Member Functions

CommandParseraddAlias (const std::string &noun, const std::string &verb, const std::string &verb2)
 Add an alias "noun verb2" to existing command "noun verb". More...
 
CommandParseraddCommand (const CommandDefinition &def, const ExecuteCommand &execute, std::underlying_type_t< AvailableIn > modes=AVAILABLE_IN_ALL)
 Add an available command. More...
 
std::vector< const CommandDefinition * > listCommands (std::string_view noun, ParseMode mode) const
 List known commands for help. More...
 
std::tuple< std::string, std::string, CommandArguments, ExecuteCommandparse (const std::vector< std::string > &tokens, ParseMode mode) const
 Parse a command line. More...
 

Detailed Description

Parses a command.

Definition at line 61 of file command-parser.hpp.

Member Function Documentation

◆ addAlias()

CommandParser & nfd::tools::nfdc::CommandParser::addAlias ( const std::string &  noun,
const std::string &  verb,
const std::string &  verb2 
)

Add an alias "noun verb2" to existing command "noun verb".

Exceptions
std::out_of_range"noun verb" does not exist

Definition at line 93 of file command-parser.cpp.

◆ addCommand()

CommandParser & nfd::tools::nfdc::CommandParser::addCommand ( const CommandDefinition def,
const ExecuteCommand execute,
std::underlying_type_t< AvailableIn modes = AVAILABLE_IN_ALL 
)

Add an available command.

Parameters
defcommand semantics definition
executea function to execute the command
modesparse modes this command should be available in, must not be AVAILABLE_IN_NONE

Definition at line 77 of file command-parser.cpp.

◆ listCommands()

std::vector< const CommandDefinition * > nfd::tools::nfdc::CommandParser::listCommands ( std::string_view  noun,
ParseMode  mode 
) const

List known commands for help.

Parameters
nounif not empty, filter results by this noun
modeinclude commands for the specified parse mode
Returns
commands in insertion order

Definition at line 100 of file command-parser.cpp.

◆ parse()

std::tuple< std::string, std::string, CommandArguments, ExecuteCommand > nfd::tools::nfdc::CommandParser::parse ( const std::vector< std::string > &  tokens,
ParseMode  mode 
) const

Parse a command line.

Parameters
tokenscommand line
modeparser mode, must be ParseMode::ONE_SHOT, other modes are not implemented
Exceptions
NoSuchCommandErrorcommand not found
CommandDefinition::Errorcommand arguments are invalid
Returns
noun, verb, arguments, execute function

Definition at line 114 of file command-parser.cpp.