CommandsRepository

This commit is contained in:
MihailRis
2024-05-09 20:16:15 +03:00
parent e1a083015e
commit 022c97b200
4 changed files with 58 additions and 8 deletions
+20
View File
@@ -23,6 +23,7 @@ namespace cmd {
};
struct CommandInput {
std::string name; // command name
dynamic::List_sptr args; // positional arguments list
dynamic::Map_sptr kwargs; // keyword arguments table
};
@@ -38,6 +39,8 @@ namespace cmd {
std::unordered_map<std::string, Argument> kwargs;
executor_func executor;
public:
Command() {}
Command(
std::string name,
std::vector<Argument> args,
@@ -52,10 +55,27 @@ namespace cmd {
return executor(input.args, input.kwargs);
}
const std::string& getName() const {
return name;
}
static Command create(std::string_view scheme, executor_func);
};
class CommandsRepository {
std::unordered_map<std::string, Command> commands;
public:
void add(std::string_view scheme, executor_func);
Command* get(const std::string& name);
};
class CommandsInterpreter {
std::unique_ptr<CommandsRepository> repository;
public:
CommandsInterpreter(std::unique_ptr<CommandsRepository> repository)
: repository(std::move(repository)){}
CommandInput parse(std::string_view text);
};
}