// // Created by Adarion on 2024/2/18. // #include "CommandParser.h" #include "PlayerDAO.h" #include "ResultPrinter.h" #include "MatchDAO.h" #include "Logger.h" namespace Mika { void CommandParser::parse(const std::string &command, std::ostream &os) { if (command == "exit") { exit(0); } try { if (command == "players") { ResultPrinter::printPlayers(PlayerDAO::getAllPlayers(), os); } else if (command.find("result") == std::string::npos) { ResultPrinter::printError(os); } else { std::string matchName = command.substr(7); try { if (command.find("detail") != std::string::npos) { auto matches = MatchDAO::getMatchDetailsByName(matchName.substr(0, matchName.size() - 7)); matches.empty() ? ResultPrinter::printNA(os) : ResultPrinter::printMatchResultsDetail(matches, os); } else { auto matches = MatchDAO::getMatchesByName(matchName); matches.empty() ? ResultPrinter::printNA(os) : ResultPrinter::printMatchResults(matches, os); } } catch (std::exception &) { ResultPrinter::printNA(os); } } } catch (std::exception &e) { LOG_ERROR(e.what()); } } } // Mika