64 γραμμές
1.9 KiB
C++
64 γραμμές
1.9 KiB
C++
#ifndef CLI_H
|
|
#define CLI_H
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "database/database.h"
|
|
#include "config.h"
|
|
|
|
class CLI
|
|
{
|
|
struct cmd
|
|
{
|
|
std::string name;
|
|
std::string helptext;
|
|
unsigned int required_args;
|
|
std::vector<cmd> subCommands;
|
|
std::function<bool(CLI *, const std::vector<std::string> &)> func;
|
|
};
|
|
|
|
private:
|
|
Database *db;
|
|
Config *conf;
|
|
|
|
protected:
|
|
bool cli_help(const std::vector<std::string> &args);
|
|
bool user_add(const std::vector<std::string> &args);
|
|
bool user_change_pw(const std::vector<std::string> &args);
|
|
bool user_rename(const std::vector<std::string> &args);
|
|
bool user_set_perms(const std::vector<std::string> &args);
|
|
bool user_list(const std::vector<std::string> &args);
|
|
bool user_show(const std::vector<std::string> &args);
|
|
|
|
std::vector<struct cmd> cmds{
|
|
{{"user",
|
|
"user operations on the database",
|
|
1,
|
|
{{{"add", "[user] [password] - creates a user", 2, {}, &CLI::user_add},
|
|
{"changepw", "[user] [password] - changes the password of user", 2, {}, &CLI::user_change_pw},
|
|
{"rename", "[user] [new name] - renames a user", 2, {}, &CLI::user_rename},
|
|
{"setperms", "[user] [perms] - sets the permissions of the user", 2, {}, &CLI::user_set_perms},
|
|
{"list", "- lists users", 2, {}, &CLI::user_list},
|
|
{"show", "[user] - show detailed information about user", 2, {}, &CLI::user_show}}},
|
|
&CLI::cli_help},
|
|
{"exit",
|
|
"exit cli",
|
|
0,
|
|
{},
|
|
[](CLI *, const std::vector<std::string> &args) -> bool
|
|
{
|
|
exit(EXIT_SUCCESS);
|
|
return true;
|
|
}},
|
|
{"help", "print this help", 0, {}, &CLI::cli_help}}};
|
|
|
|
bool processCommand(const std::vector<CLI::cmd> &commands, std::string cmd, const std::vector<std::string> &args);
|
|
|
|
public:
|
|
CLI(Config &config, Database &d);
|
|
void startInteractive();
|
|
bool processCommand(std::string cmd, const std::vector<std::string> &args);
|
|
};
|
|
|
|
#endif // CLI_H
|