summaryrefslogtreecommitdiffstats
path: root/src/Client/CommandParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Client/CommandParser.cpp')
-rw-r--r--src/Client/CommandParser.cpp45
1 files changed, 23 insertions, 22 deletions
diff --git a/src/Client/CommandParser.cpp b/src/Client/CommandParser.cpp
index be2383a..f231082 100644
--- a/src/Client/CommandParser.cpp
+++ b/src/Client/CommandParser.cpp
@@ -18,11 +18,11 @@
*/
#include "CommandParser.h"
+#include "Application.h"
#include "InformationManager.h"
#include "SystemCommands.h"
#include "UserCommands.h"
-#include <Core/Logger.h>
#include <Core/Tokenizer.h>
#include <Common/RequestManager.h>
@@ -52,8 +52,6 @@ const CommandParser::Command CommandParser::commands[] = {
{{0}, 0, 0, 0, 0}
};
-CommandParser CommandParser::commandParser;
-
const CommandParser::Command* CommandParser::findCommand(const std::string& command) {
for(int i = 0; commands[i].commands[0] != 0; ++i) {
@@ -71,12 +69,12 @@ void CommandParser::printUsage(const std::string& command) {
const CommandParser::Command *cmd = findCommand(command);
if(cmd)
- Core::Logger::logf("Usage: %s\n", cmd->cmdline);
+ std::cerr << "Usage: " << cmd->cmdline << std::endl;
}
std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::vector<std::string> &args, bool mustBeActive) {
- const std::map<std::string, Common::HostInfo>& hosts = InformationManager::get()->getDaemons();
+ const std::map<std::string, Common::HostInfo>& hosts = application->getInformationManager()->getDaemons();
std::map<std::string, Common::HostInfo> ret;
for(std::vector<std::string>::const_iterator arg = args.begin(); arg != args.end(); ++arg) {
@@ -88,7 +86,7 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
}
if(ret.empty())
- Core::Logger::log("No hosts active.");
+ std::cerr << "No hosts active." << std::endl;
}
else {
ret = hosts;
@@ -98,9 +96,9 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
std::map<std::string, Common::HostInfo>::const_iterator host = hosts.find(*arg);
if(host == hosts.end())
- Core::Logger::logf(Core::Logger::ERROR, "Host '%s' doesn't exist.", arg->c_str());
+ std::cerr << "Host '" << *arg << "' doesn't exist." << std::endl;
else if(mustBeActive && host->second.getState() == Common::HostInfo::INACTIVE)
- Core::Logger::logf(Core::Logger::WARNING, "Host '%s' is inactive.", arg->c_str());
+ std::cerr << "Host '" << *arg << "' is inactive." << std::endl;
else
ret.insert(*host);
}
@@ -109,7 +107,7 @@ std::map<std::string, Common::HostInfo> CommandParser::parseHostList(const std::
return ret;
}
-void CommandParser::helpCommand(const std::vector<std::string> &args, Common::Connection *connection _UNUSED_PARAMETER_) {
+void CommandParser::helpCommand(const std::vector<std::string> &args) {
if(args.size() == 1) {
std::cout << "Available commands:" << std::endl << std::endl;
@@ -130,16 +128,16 @@ void CommandParser::helpCommand(const std::vector<std::string> &args, Common::Co
std::cout << command->longdesc << std::endl << std::endl;
}
else
- Core::Logger::logf(Core::Logger::WARNING, "%s: Command '%s' doesn't exist.", args[0].c_str(), args[1].c_str());
+ std::cerr << args[0] << ": Command '" << args[1] << "' doesn't exist." << std::endl;
}
else {
- Core::Logger::logf(Core::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
printUsage("help");
}
}
-void CommandParser::listHostsCommand(const std::vector<std::string> &args, Common::Connection *connection _UNUSED_PARAMETER_) {
- const std::map<std::string, Common::HostInfo>& hosts = InformationManager::get()->getDaemons();
+void CommandParser::listHostsCommand(const std::vector<std::string> &args) {
+ const std::map<std::string, Common::HostInfo>& hosts = application->getInformationManager()->getDaemons();
if(args.size() == 1) {
if(hosts.empty()) {
@@ -167,7 +165,7 @@ void CommandParser::listHostsCommand(const std::vector<std::string> &args, Commo
std::cout << std::endl;
}
else if(args.size() > 2) {
- Core::Logger::logf(Core::Logger::ERROR, "%s: Too many arguments.", args[0].c_str());
+ std::cerr << args[0] << ": Too many arguments." << std::endl;
printUsage("list_hosts");
}
else if(args[1] == "-a") {
@@ -185,23 +183,23 @@ void CommandParser::listHostsCommand(const std::vector<std::string> &args, Commo
std::cout << std::endl;
}
else {
- Core::Logger::logf(Core::Logger::ERROR, "%s: Don't understand argument '%s'.", args[0].c_str(), args[1].c_str());
+ std::cerr << args[0] << ": Don't understand argument '" << args[1] << "'." << std::endl;
printUsage("list_hosts");
}
}
-void CommandParser::exitCommand(const std::vector<std::string> &args _UNUSED_PARAMETER_, Common::Connection *connection) {
- boost::shared_ptr<Common::Requests::DisconnectRequest> request(new Common::Requests::DisconnectRequest);
+void CommandParser::exitCommand(const std::vector<std::string> &args _UNUSED_PARAMETER_) {
+ boost::shared_ptr<Common::Requests::DisconnectRequest> request(new Common::Requests::DisconnectRequest(application));
- Common::RequestManager::get()->sendRequest(connection, request);
+ application->getRequestManager()->sendRequest(connection, request);
request->wait();
std::pair<boost::shared_ptr<const Common::XmlPacket>, Core::Exception> result = request->getResult();
if(result.second)
- Core::Logger::logf(Core::Logger::ERROR, "An error occurred during your request: %s.", result.second.strerror().c_str());
+ std::cerr << "An error occurred during your request: " << result.second.strerror() << "." << std::endl;
else
- commandParser.disconnect = true;
+ disconnect = true;
}
bool CommandParser::parse(const std::string &cmd) {
@@ -215,12 +213,15 @@ bool CommandParser::parse(const std::string &cmd) {
const Command* command = findCommand(splitCmd[0]);
if(command)
- command->function(splitCmd, connection);
+ command->function(this, splitCmd);
else
- Core::Logger::logf(Core::Logger::ERROR, "Unknown command '%s'.", splitCmd[0].c_str());
+ std::cerr << "Unknown command '" << splitCmd[0] << "'." << std::endl;
return true;
}
+CommandParser::CommandParser(Application *application0, Common::Connection *connection0)
+: application(application0), connection(connection0), disconnect(false) {}
+
}
}