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  Error
 

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< AvailableIn >::type modes=AVAILABLE_IN_ALL)
 add an available command More...
 
std::vector< const CommandDefinition * > listCommands (const std::string &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 62 of file command-parser.hpp.

Member Function Documentation

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 88 of file command-parser.cpp.

CommandParser & nfd::tools::nfdc::CommandParser::addCommand ( const CommandDefinition def,
const ExecuteCommand execute,
std::underlying_type< AvailableIn >::type  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 73 of file command-parser.cpp.

std::vector< const CommandDefinition * > nfd::tools::nfdc::CommandParser::listCommands ( const std::string &  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 95 of file command-parser.cpp.

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
Errorcommand is not found
CommandDefinition::Errorcommand arguments are invalid
Returns
noun, verb, arguments, execute function

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