X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=setlogfilecommand.cpp;h=41c8e743122399563b8367fda6a9d4a94f9bda86;hp=19f3ed129ab85b9f66dbea06c56637ea2f8daa42;hb=b25ede2ad307ae76f8a610443e0ec3ec69621ce7;hpb=260ae19c36cb11a53ddc5a75b5e507f8dd8b31d6 diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp index 19f3ed1..41c8e74 100644 --- a/setlogfilecommand.cpp +++ b/setlogfilecommand.cpp @@ -9,19 +9,52 @@ #include "setlogfilecommand.h" + +//********************************************************************************************************************** +vector SetLogFileCommand::setParameters(){ + try { + CommandParameter pappend("append", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pappend); + CommandParameter pname("name", "String", "", "", "", "", "","",false,true,true); parameters.push_back(pname); + CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir); + CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; + } + catch(exception& e) { + m->errorOut(e, "SetLogFileCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string SetLogFileCommand::getHelpString(){ + try { + string helpString = ""; + helpString += "The set.logfile command can be used to provide a specific name for your logfile and/or to append the log generated by mothur to an existing file.\n"; + helpString += "The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n"; + helpString += "The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n"; + helpString += "Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n"; + helpString += "Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "SetLogFileCommand", "getHelpString"); + exit(1); + } +} //********************************************************************************************************************** SetLogFileCommand::SetLogFileCommand(string option) { try { - abort = false; + abort = false; calledHelp = false; //allow user to run help - if(option == "help") { help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string Array[] = {"name","append","outputdir","inputdir"}; - vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -44,35 +77,22 @@ SetLogFileCommand::SetLogFileCommand(string option) { exit(1); } } -//********************************************************************************************************************** - -void SetLogFileCommand::help(){ - try { - m->mothurOut("The set.logfile command can be used to provide a specific name for your logfile and/or to append the log generated by mothur to an existing file.\n"); - m->mothurOut("The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n"); - m->mothurOut("The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n"); - m->mothurOut("Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n\n"); - } - catch(exception& e) { - m->errorOut(e, "SetLogFileCommand", "help"); - exit(1); - } -} -//********************************************************************************************************************** - -SetLogFileCommand::~SetLogFileCommand(){} //********************************************************************************************************************** int SetLogFileCommand::execute(){ try { - if (abort == true) { return 0; } - - commandFactory = CommandFactory::getInstance(); + if (abort == true) { if (calledHelp) { return 0; } return 2; } - commandFactory->setLogfileName(name, append); + commandFactory = CommandFactory::getInstance(); + + string directory = m->hasPath(name); + if (directory == "") { + commandFactory->setLogfileName(name, append); + }else if (m->dirCheck(directory)) { + commandFactory->setLogfileName(name, append); + } return 0; }