2 * setlogfilecommand.cpp
5 * Created by westcott on 4/27/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "setlogfilecommand.h"
13 //**********************************************************************************************************************
14 vector<string> SetLogFileCommand::setParameters(){
16 CommandParameter pappend("append", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pappend);
17 CommandParameter pname("name", "String", "", "", "", "", "","",false,true,true); parameters.push_back(pname);
18 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
19 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
21 vector<string> myArray;
22 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
26 m->errorOut(e, "SetLogFileCommand", "setParameters");
30 //**********************************************************************************************************************
31 string SetLogFileCommand::getHelpString(){
33 string helpString = "";
34 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";
35 helpString += "The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n";
36 helpString += "The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n";
37 helpString += "Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n";
38 helpString += "Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n";
42 m->errorOut(e, "SetLogFileCommand", "getHelpString");
46 //**********************************************************************************************************************
48 SetLogFileCommand::SetLogFileCommand(string option) {
50 abort = false; calledHelp = false;
52 //allow user to run help
53 if(option == "help") { help(); abort = true; calledHelp = true; }
54 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
57 vector<string> myArray = setParameters();
59 OptionParser parser(option);
60 map<string, string> parameters = parser.getParameters();
62 ValidParameters validParameter;
63 //check to make sure all parameters are valid for command
64 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
65 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
68 name = validParameter.validFile(parameters, "name", false);
69 if (name == "not found") { m->mothurOut("name is a required parameter for the set.logfile command."); abort = true; }
71 string temp = validParameter.validFile(parameters, "append", false); if (temp == "not found") { temp = "F"; }
72 append = m->isTrue(temp);
76 m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
81 //**********************************************************************************************************************
83 int SetLogFileCommand::execute(){
86 if (abort == true) { if (calledHelp) { return 0; } return 2; }
88 commandFactory = CommandFactory::getInstance();
90 string directory = m->hasPath(name);
91 if (directory == "") {
92 commandFactory->setLogfileName(name, append);
93 }else if (m->dirCheck(directory)) {
94 commandFactory->setLogfileName(name, append);
100 m->errorOut(e, "SetLogFileCommand", "execute");
104 //**********************************************************************************************************************/