Parses a command. More...
#include <tools/nfdc/command-parser.hpp>
Classes | |
class | NoSuchCommandError |
Public Member Functions | |
CommandParser & | addAlias (const std::string &noun, const std::string &verb, const std::string &verb2) |
Add an alias "noun verb2" to existing command "noun verb". More... | |
CommandParser & | addCommand (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, ExecuteCommand > | parse (const std::vector< std::string > &tokens, ParseMode mode) const |
Parse a command line. More... | |
Parses a command.
Definition at line 62 of file command-parser.hpp.
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".
std::out_of_range | "noun verb" does not exist |
Definition at line 93 of file command-parser.cpp.
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.
def | command semantics definition |
execute | a function to execute the command |
modes | parse modes this command should be available in, must not be AVAILABLE_IN_NONE |
Definition at line 77 of file command-parser.cpp.
std::vector< const CommandDefinition * > nfd::tools::nfdc::CommandParser::listCommands | ( | std::string_view | noun, |
ParseMode | mode | ||
) | const |
List known commands for help.
noun | if not empty, filter results by this noun |
mode | include commands for the specified parse mode |
Definition at line 100 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.
tokens | command line |
mode | parser mode, must be ParseMode::ONE_SHOT, other modes are not implemented |
NoSuchCommandError | command not found |
CommandDefinition::Error | command arguments are invalid |
Definition at line 114 of file command-parser.cpp.