/* * CommandParser.h * * Copyright (C) 2008 Matthias Schiffer * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ #ifndef MAD_CLIENT_COMMANDPARSER_H_ #define MAD_CLIENT_COMMANDPARSER_H_ #include "CommandManager.h" #include #include #include #include namespace Mad { namespace Common { class Connection; } namespace Client { class CommandParser { private: struct Command { const char* commands[3]; const char* cmdline; const char* desc; const char* longdesc; void (CommandParser::*funcPtr) (const std::vector &args); }; static const Command commands[]; static CommandParser commandParser; Common::Connection *connection; const Command* findCommand(const std::string& command); void printUsage(const std::string& command); std::map parseHostList(const std::vector &args, bool mustBeActive = false); void fsinfoCommand(const std::vector &args); void helpCommand(const std::vector &args); void listHostsCommand(const std::vector &args); void rebootCommand(const std::vector &args); void shutdownCommand(const std::vector &args); void statusCommand(const std::vector &args); void userInfoCommand(const std::vector &args); void listUsersCommand(const std::vector &args); void listUserGroupsCommand(const std::vector &args); void listGroupsCommand(const std::vector &args); void listGroupUsersCommand(const std::vector &args); void exitCommand(const std::vector&); CommandParser() : connection(0) {} public: static CommandParser *get() { return &commandParser; } Common::Connection *getConnection() const { return connection; } void setConnection(Common::Connection *con) { connection = con; } bool parse(const std::string &cmd); void requestDisconnect() { exitCommand(std::vector()); } }; } } #endif /* MAD_CLIENT_COMMANDPARSER_H_ */