renderbug/lib/Figments/Command.h

34 lines
718 B
C
Raw Normal View History

#pragma once
#include <Arduino.h>
class Args {
private:
String *str;
public:
Args(String *str) : str(str) {}
String operator[](int pos) {
char buf[64];
strncpy(buf, str->c_str(), sizeof(buf));
char *args = strtok(buf, " ");
while (pos > 0 && args != NULL) {
args = strtok(NULL, " ");
pos--;
}
if (args == NULL) {
return String();
}
return String(args);
}
};
struct CommandList;
struct Command {
using Executor = std::function<void(Args&, Print& output)>;
Executor func;
const char* name = NULL;
Command();
Command(const char* name, Executor func) : name(name), func(func) {}
};