25 #ifndef ACE_UTILS_CLI_COMMAND_DISPATCHER_H
26 #define ACE_UTILS_CLI_COMMAND_DISPATCHER_H
28 #include "CommandHandler.h"
31 class __FlashStringHelper;
69 mNumCommands(numCommands),
78 void runCommand(Print& printer,
char* line)
const;
88 static uint8_t
tokenize(
char* line,
const char** argv, uint8_t argvSize) {
89 char* token = strtok(line, DELIMS);
91 while (token !=
nullptr && argc < argvSize) {
94 token = strtok(
nullptr, DELIMS);
109 for (uint8_t i = 0; i < mNumCommands; i++) {
111 if (command->
getName().compareTo(ace_common::FCString(cmd)) == 0) {
124 void helpCommandHandler(Print& printer,
int argc,
const char*
const* argv)
128 void helpAll(Print& printer)
const;
131 bool helpSpecific(Print& printer,
const char* cmd)
const;
134 static void printHelp(Print& printer,
const CommandHandler* command);
137 void findAndRunCommand(Print& printer,
const char* cmd,
138 int argc,
const char*
const* argv)
const;
141 static const char DELIMS[];
144 uint8_t
const mNumCommands;
145 const char**
const mArgv;
146 uint8_t
const mArgvSize;
A class that tokenizes a line containing tokens separated on whitespace boundaries,...
CommandDispatcher(const CommandHandler *const *commands, uint8_t numCommands, const char **argv, uint8_t argvSize)
Constructor.
static uint8_t tokenize(char *line, const char **argv, uint8_t argvSize)
Tokenize the line, separating tokens delimited by whitespace (space, formfeed, carriage return,...
const CommandHandler * findCommand(const char *cmd) const
Find the CommandHandler of the given command name.
void runCommand(Print &printer, char *line) const
Tokenize the given 'line', run the matching command handler, and send output to the 'printer'.
Signature for a command handler.
ace_common::FCString getName() const
Return the name of the command.