CLI: Implement category delete,show,list

This commit is contained in:
Albert S. 2021-10-12 20:02:43 +02:00
부모 c18178a50f
커밋 420e541e75
2개의 변경된 파일41개의 추가작업 그리고 0개의 파일을 삭제

31
cli.cpp
파일 보기

@ -249,3 +249,34 @@ std::pair<bool, std::string> CLIHandler::version(const std::vector<std::string>
{
return {true, get_version_string()};
}
std::pair<bool, std::string> CLIHandler::category_list(const std::vector<std::string> &args)
{
auto categoryDao = this->db->createCategoryDao();
auto categories = categoryDao->fetchList(QueryOption{});
std::stringstream stream;
for(std::string &cat : categories)
{
stream << cat << std::endl;
}
return {true, stream.str()};
}
std::pair<bool, std::string> CLIHandler::category_delete(const std::vector<std::string> &args)
{
auto categoryDao = this->db->createCategoryDao();
categoryDao->deleteCategory(args.at(0));
return {true, ""};
}
std::pair<bool, std::string> CLIHandler::category_show(const std::vector<std::string> &args)
{
auto categoryDao = this->db->createCategoryDao();
auto members = categoryDao->fetchMembers(args.at(0), QueryOption{});
std::stringstream stream;
for(std::string &member : members)
{
stream << member << std::endl;
}
return {true, stream.str()};
}

10
cli.h
파일 보기

@ -33,6 +33,9 @@ class CLIHandler
std::pair<bool, std::string> page_list(const std::vector<std::string> &args);
std::pair<bool, std::string> pageperms_set_permissions(const std::vector<std::string> &args);
std::pair<bool, std::string> version(const std::vector<std::string> &args);
std::pair<bool, std::string> category_list(const std::vector<std::string> &args);
std::pair<bool, std::string> category_delete(const std::vector<std::string> &args);
std::pair<bool, std::string> category_show(const std::vector<std::string> &args);
std::vector<struct cmd> cmds{
{{"user",
@ -50,6 +53,13 @@ class CLIHandler
1,
{{{"list", "- lists existing pages", 0, {}, &CLIHandler::page_list}}},
&CLIHandler::cli_help},
{"category",
"operation on categories",
1,
{{{"list", "- lists existing categories", 0, {}, &CLIHandler::category_list},
{"delete", " - deletes a category", 1, {}, &CLIHandler::category_delete},
{"show", " - shows pages of a category", 1, {}, &CLIHandler::category_show}}},
&CLIHandler::cli_help},
{"pageperms",
"set permissions on pages",
1,