diff options
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r-- | src/Client/CommandParser.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 1a5a96c..1ba986f 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -18,9 +18,9 @@ */ #include "CommandParser.h" +#include "InformationManager.h" #include "Requests/CoreStatusRequest.h" #include "Requests/DaemonCommandRequest.h" -#include "Requests/DaemonListRequest.h" #include "Requests/DaemonStatusRequest.h" #include <Common/Exception.h> #include <Common/Logger.h> @@ -40,7 +40,7 @@ const CommandParser::Command CommandParser::commands[] = { {{"help", "?", 0}, "help [command]", "Displays usage information about commands", "Displays usage information about a command. If no command is given, a list of all available commands is displayed.", &CommandParser::helpCommand}, {{"list_hosts", "hosts", 0}, "list_hosts [-a]", "Lists the currently active hosts", "Lists the currently active hosts.\n\n -a\tAlso list inactive hosts", &CommandParser::listHostsCommand}, {{"reboot", 0}, "reboot host", "Reboots a host", "Reboots a host.", &CommandParser::rebootCommand}, - {{"shutdown", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand}, + {{"shutdown", "halt", 0}, "shutdown host", "Shuts a host down", "Shuts a host down.", &CommandParser::shutdownCommand}, {{"status", "st", 0}, "status [host]", "Displays status information", "Displays host status information. If no host is given, server status information is displayed.", &CommandParser::statusCommand}, {{"exit", "quit", 0}, "exit", "Closes the connection and quits the client", "Closes the connection and quits the client.", &CommandParser::exitCommand}, {{0}, 0, 0, 0, 0} @@ -95,36 +95,55 @@ void CommandParser::helpCommand(const std::vector<std::string> &args) { } void CommandParser::listHostsCommand(const std::vector<std::string> &args) { + const std::map<std::string, Common::HostInfo>& hosts = InformationManager::getInformationManager()->getDaemons(); + if(args.size() == 1) { - Common::RequestManager::getRequestManager()->sendRequest(connection, - std::auto_ptr<Common::RequestBase>( - new Requests::DaemonListRequest( - sigc::bind(sigc::mem_fun(commandManager, &CommandManager::daemonListRequestFinished), false) - ) - ) - ); + if(hosts.empty()) { + std::cout << "The host list is empty." << std::endl << std::endl; + return; + } + + bool output = false; + + for(std::map<std::string, Common::HostInfo>::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + if(host->second.getState() == Common::HostInfo::INACTIVE) + continue; + + if(!output) { + std::cout << "Active hosts:" << std::endl; + output = true; + } + + std::cout << " " << host->first << std::endl; + } + + if(!output) + std::cout << "No active hosts." << std::endl; + + std::cout << std::endl; } else if(args.size() > 2) { Common::Logger::logf(Common::Logger::ERROR, "%s: Too many arguments.", args[0].c_str()); printUsage("list_hosts"); - return; } else if(args[1] == "-a") { - Common::RequestManager::getRequestManager()->sendRequest(connection, - std::auto_ptr<Common::RequestBase>( - new Requests::DaemonListRequest( - sigc::bind(sigc::mem_fun(commandManager, &CommandManager::daemonListRequestFinished), true) - ) - ) - ); + if(hosts.empty()) { + std::cout << "The host list is empty." << std::endl << std::endl; + return; + } + + std::cout << "Host list:" << std::endl; + + for(std::map<std::string, Common::HostInfo>::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + std::cout << " " << host->first << " (" << (host->second.getState() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; + } + + std::cout << std::endl; } else { - Common::Logger::logf(Common::Logger::ERROR, "%s: Don't unterstand argument '%s'.", args[0].c_str(), args[1].c_str()); + Common::Logger::logf(Common::Logger::ERROR, "%s: Don't understand argument '%s'.", args[0].c_str(), args[1].c_str()); printUsage("list_hosts"); - return; } - - commandManager.activeRequests++; } void CommandParser::rebootCommand(const std::vector<std::string> &args) { |