int main(int argc, char* argv[]) { mreal::initPrecision(); mreal::initRand(); CommandParser commandParser; initCommands(&commandParser); CommandFactory commandFactory; try { int commandCode = UNKNOWN_COMMAND; CommandParams commandParams; commandParser.getCommandCodeAndParams(argc, argv, commandCode, commandParams); ContextPtr pContext = Context::setup(DRY_MODE, ".3app"); CommandPtr pCommand = commandFactory.getCommand(commandCode, commandParams); pCommand->execute(); _destroy(pCommand); delete pContext; } catch(std::exception const& e) { std::cout << e.what() << std::endl; printSyntaxMessage(); } }
void XMLReader::parseAction(QXmlStreamReader& xml, queue<Command*>* ListOfCommand) { CommandFactory cmdFactory; if (xml.tokenType() != QXmlStreamReader::StartElement && xml.name() == "action") return ;//ListOfCommand; xml.readNext(); while(!(xml.tokenType() == QXmlStreamReader::EndElement && xml.name() == "action")) { if(xml.tokenType() == QXmlStreamReader::StartElement) { if(xml.name() == "type") { xml.readNext(); ListOfCommand->push(cmdFactory.CreateCommand(xml.text().toString().toStdString())); //cout<<xml.text().toString().toStdString()<<endl; } } xml.readNext(); } //return ListOfCommand; }
void ConsoleController::processInput(const CommandFactory& commandFactory) { std::string line; while (std::getline(std::cin, line)) { auto args = split(line, ' '); if (args.size() >= 1) { auto command = commandFactory.getCommand(args[0]); if (command) { command->execute(shared_from_this(), args); if (args[0] == "exit") break; } } } }
int LoadLogfileCommand::execute(){ try { if (abort == true) { if (calledHelp) { return 0; } return 2; } m->mothurOutEndLine(); m->mothurOut("Extracting current files names..."); m->mothurOutEndLine(); m->mothurOutEndLine(); CommandFactory* cFactory; cFactory = CommandFactory::getInstance(); ifstream in; m->openInputFile(logfile, in); set<string> currentTypes = m->getCurrentTypes(); map<string, string> currentFiles; string commandName = ""; bool skip = false; string line = ""; while (!in.eof()) { if (m->control_pressed) { break; } if (!skip) { line = m->getline(in); m->gobble(in); } m->gobble(in); //look for "mothur >" int pos = line.find("mothur > "); //command line int pos2 = line.find("Output File "); //indicates command completed and we can update the current file int pos3 = line.find("/*****************"); //skipping over parts where a command runs another command if (pos3 != string::npos) { while (!in.eof()) { if (m->control_pressed) { break; } line = m->getline(in); m->gobble(in); int posTemp = line.find("/*****************"); if (posTemp != string::npos) { break; } } } if (pos != string::npos) { skip=false; //extract command name and option string string input = line.substr(pos+9); CommandOptionParser parser(input); commandName = parser.getCommandString(); string options = parser.getOptionString(); //parse out parameters in option string map<string,string> parameters; OptionParser optionParser(options, parameters); for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { if (currentTypes.count((it->first)) != 0) { //if this is a type we save if (it->second != "current") { currentFiles[it->first] = it->second; }//save the input file name as current } } }else if (pos2 != string::npos) { //read file output file names vector<string> theseOutputNames; while (!in.eof()) { if (m->control_pressed) { break; } line = m->getline(in); m->gobble(in); int pos = line.find("mothur > "); if (pos != string::npos) { skip = true; break; } else { theseOutputNames.push_back(line); } } //ask command for the output names for each type based on inputs Command* command = cFactory->getCommand(commandName); map<string, vector<string> > thisOutputTypes = command->getOutputFiles(); for (map<string, vector<string> >::iterator it = thisOutputTypes.begin(); it != thisOutputTypes.end(); it++) { if (currentTypes.count((it->first)) != 0) { //do we save this type //if yes whats its tag map<string, string>::iterator itCurrentFiles = currentFiles.find(it->first); string thisTypesCurrentFile = ""; if (itCurrentFiles != currentFiles.end()) { thisTypesCurrentFile = itCurrentFiles->second; } //outputfilename pattern for this input type string pattern = command->getOutputPattern(it->first); updateCurrent(pattern, it->first, thisTypesCurrentFile, theseOutputNames, currentFiles); //cout << "current=\n\n"; //for (map<string, string>::iterator itcc = currentFiles.begin(); itcc != currentFiles.end(); itcc++) { // cout << itcc->first << '\t' << itcc->second << endl; // } } } } } in.close(); if (m->control_pressed) { return 0; } //output results string inputString = ""; for (map<string, string>::iterator it = currentFiles.begin(); it != currentFiles.end(); it++) { inputString += it->first + "=" + it->second + ","; } if (inputString != "") { inputString = inputString.substr(0, inputString.length()-1); m->mothurOutEndLine(); m->mothurOut("/******************************************/"); m->mothurOutEndLine(); m->mothurOut("Running command: set.current(" + inputString + ")"); m->mothurOutEndLine(); m->mothurCalling = true; Command* currentCommand = new SetCurrentCommand(inputString); currentCommand->execute(); delete currentCommand; m->mothurCalling = false; m->mothurOut("/******************************************/"); m->mothurOutEndLine(); } return 0; } catch(exception& e) { m->errorOut(e, "LoadLogfileCommand", "execute"); exit(1); } }