31 #include "CommandDispatcher.h" 37 const char CommandDispatcher::DELIMS[] =
" \f\r\n\t\v";
41 if (statusCode == STATUS_BUFFER_OVERFLOW) {
42 mPrinter.print(F(
"BufferOverflow: "));
43 mPrinter.println(line);
44 }
else if (statusCode == STATUS_FLUSH_TO_EOL) {
45 mPrinter.print(F(
"FlushToEOL: "));
46 mPrinter.println(line);
48 mPrinter.print(F(
"UnknownError: "));
49 mPrinter.print(statusCode);
50 mPrinter.print(F(
": "));
51 mPrinter.println(line);
56 Print& printer,
int argc,
const char** argv)
const {
58 const char* cmd = argv[1];
61 if (strcmp(cmd,
"help") == 0) {
62 printer.println(F(
"Usage: help [command]"));
68 printer.print(F(
"Unknown command: "));
71 printer.println(F(
"Commands:"));
72 printer.println(F(
" help [command]"));
78 for (uint8_t i = 0; i < mNumCommands; i++) {
87 if (command !=
nullptr) {
88 printer.print(F(
"Usage: "));
109 int argc =
tokenize(line, mArgv, mArgvSize);
110 if (argc == 0)
return;
111 const char* cmd = mArgv[0];
114 if (strcmp(cmd,
"help") == 0) {
123 const char* cmd,
int argc,
const char** argv)
const {
125 if (command !=
nullptr) {
126 command->
run(mPrinter, argc, argv);
130 mPrinter.print(F(
"Unknown command: "));
131 mPrinter.println(cmd);
Signature for a command handler.
bool helpSpecific(Print &printer, const char *cmd) const
Print helpString of specific cmd.
void runCommand(char *line) const
Tokenize the given line and run the command handler.
bool isNull() const
Return if this is a null string.
const CommandHandler * findCommand(const char *cmd) const
Find the CommandHandler of the given command name.
void findAndRunCommand(const char *cmd, int argc, const char **argv) const
Find and run the given command.
void helpAll(Print &printer) const
Print help on all commands.
static uint8_t tokenize(char *line, const char **argv, uint8_t argvSize)
Tokenize the line, separating tokens delimited by whitespace (space, formfeed, carriage return...
static void printHelp(Print &printer, const CommandHandler *command)
Print help string for the given command.
void printLineError(const char *line, uint8_t statusCode) const
Print the input line that caused an error along with its status code.
size_t printTo(Print &printer) const
Convenience method for printing an FCString to printer.
FCString getHelpString() const
Return the help string of the command.
void helpCommandHandler(Print &printer, int argc, const char **argv) const
Handle the 'help' command.
virtual void run(Print &printer, int argc, const char **argv) const =0
Run the command.
FCString getName() const
Return the name of the command.