From 793a0789858734141dfa12d2ab3dd6ea3ed293e8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 18 Sep 2008 21:31:28 +0200 Subject: list_hosts zeigt entweder alle oder nur aktive Hosts an --- src/Client/CommandParser.cpp | 63 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 9 deletions(-) (limited to 'src/Client/CommandParser.cpp') diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp index 76178dc..34c7e4f 100644 --- a/src/Client/CommandParser.cpp +++ b/src/Client/CommandParser.cpp @@ -30,13 +30,14 @@ #include #include +#include namespace Mad { namespace Client { 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", "Lists the currently active hosts", "Lists the currently active hosts", &CommandParser::listHostsCommand}, + {{"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}, {{"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} @@ -143,10 +144,37 @@ void CommandParser::helpCommand(const std::vector &args) { } } -void CommandParser::listHostsCommand(const std::vector&) { - activeRequests++; +void CommandParser::listHostsCommand(const std::vector &args) { + if(args.size() == 1) { + Common::RequestManager::getRequestManager()->sendRequest(connection, + std::auto_ptr( + new Requests::DaemonListRequest( + sigc::bind(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished), false) + ) + ) + ); + } + else if(args.size() > 2) { + Common::Logger::log(Common::Logger::ERROR, args[0] + ": Too many arguments."); + printUsage("list_hosts"); + return; + } + else if(args[1] == "-a") { + Common::RequestManager::getRequestManager()->sendRequest(connection, + std::auto_ptr( + new Requests::DaemonListRequest( + sigc::bind(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished), true) + ) + ) + ); + } + else { + Common::Logger::log(Common::Logger::ERROR, args[0] + ": Don't unterstand argument '" + args[1] + "'."); + printUsage("list_hosts"); + return; + } - Common::RequestManager::getRequestManager()->sendRequest(connection, std::auto_ptr(new Requests::DaemonListRequest(sigc::mem_fun(this, &CommandParser::daemonListRequestFinished)))); + activeRequests++; } void CommandParser::statusCommand(const std::vector &args) { @@ -182,18 +210,35 @@ void CommandParser::coreStatusRequestFinished(const Common::Request &request) { +void CommandParser::daemonListRequestFinished(const Common::Request &request, bool all) { try { const std::vector& hosts = request.getResult().getHostInfo(); if(hosts.empty()) { - std::cout << "There aren't any active hosts." << std::endl << std::endl; + std::cout << "The host list is empty." << std::endl << std::endl; } else { - std::cout << "Host list:" << std::endl; + bool output = false; + + for(std::vector::const_iterator host = hosts.begin(); host != hosts.end(); ++host) { + if(host->getStatus() == Common::HostInfo::INACTIVE && !all) + continue; + + if(!output) { + std::cout << (all ? "Host list:" : "Active hosts:") << std::endl; + output = true; + } + + std::cout << " " << host->getName(); + + if(all) + std::cout << " (" << (host->getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")"; + + std::cout << std::endl; + } - for(std::vector::const_iterator host = hosts.begin(); host != hosts.end(); ++host) - std::cout << "\t" << host->getName() << " (" << (host->getStatus() == Common::HostInfo::RUNNING ? "running" : "inactive") << ")" << std::endl; + if(!output) + std::cout << "No active hosts." << std::endl; std::cout << std::endl; } -- cgit v1.2.3