#ifndef CLI_H #define CLI_H #include #include #include #include "database/database.h" #include "config.h" class CLI { struct cmd { std::string name; std::string helptext; unsigned int required_args; std::vector subCommands; std::function &)> func; }; private: Database *db; Config *conf; protected: bool cli_help(const std::vector &args); bool user_add(const std::vector &args); bool user_change_pw(const std::vector &args); bool user_rename(const std::vector &args); bool user_set_perms(const std::vector &args); bool user_list(const std::vector &args); bool user_show(const std::vector &args); std::vector 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 &args) -> bool { exit(EXIT_SUCCESS); return true; }}, {"help", "print this help", 0, {}, &CLI::cli_help}}}; bool processCommand(const std::vector &commands, std::string cmd, const std::vector &args); public: CLI(Config &config, Database &d); void startInteractive(); bool processCommand(std::string cmd, const std::vector &args); }; #endif // CLI_H