diff options
Diffstat (limited to 'src/Client/UserCommands.cpp')
-rw-r--r-- | src/Client/UserCommands.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/Client/UserCommands.cpp b/src/Client/UserCommands.cpp index 43131c7..b93de94 100644 --- a/src/Client/UserCommands.cpp +++ b/src/Client/UserCommands.cpp @@ -320,6 +320,103 @@ void UserCommands::deleteUserCommand(CommandParser *commandParser, const std::ve } } +void UserCommands::addGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { + if(args.size() < 3) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("add_group"); + return; + } + if(args.size() > 3) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("add_group"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[2].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("add_group"); + return; + } + + try { + commandParser->application->getUserManager()->addGroup(Common::GroupInfo(gid, args[2])); + + std::cout << "Group added." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + +void UserCommands::updateGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { + if(args.size() < 4) { + std::cerr << args[0] << ": Too few arguments." << std::endl; + commandParser->printUsage("update_group"); + return; + } + if(args.size() > 4) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("update_group"); + return; + } + + char *endptr; + unsigned long origGid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse the old group id." << std::endl; + commandParser->printUsage("update_group"); + return; + } + + unsigned long gid = std::strtoul(args[2].c_str(), &endptr, 10); + if(args[2].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse the new group id." << std::endl; + commandParser->printUsage("update_group"); + return; + } + + try { + commandParser->application->getUserManager()->updateGroup(origGid, Common::GroupInfo(gid, args[3])); + + std::cout << "Group updated." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + +void UserCommands::deleteGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { + if(args.size() < 2) { + std::cerr << args[0] << ": No group id given." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + if(args.size() > 2) { + std::cerr << args[0] << ": Too many arguments." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + + char *endptr; + unsigned long gid = std::strtoul(args[1].c_str(), &endptr, 10); + if(args[1].empty() || *endptr != '\0') { + std::cerr << args[0] << ": Unable to parse group id." << std::endl; + commandParser->printUsage("delete_group"); + return; + } + + try { + commandParser->application->getUserManager()->deleteGroup(gid); + + std::cout << "Group deleted." << std::endl; + } + catch(Core::Exception e) { + std::cerr << "An error occurred during your request: " << e.strerror() << "." << std::endl; + } +} + void UserCommands::addUserToGroupCommand(CommandParser *commandParser, const std::vector<std::string> &args) { if(args.size() < 3) { std::cerr << args[0] << ": Too few arguments." << std::endl; |