]> git.donarmstrong.com Git - mothur.git/blob - setlogfilecommand.cpp
changes while testing
[mothur.git] / setlogfilecommand.cpp
1 /*
2  *  setlogfilecommand.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 4/27/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "setlogfilecommand.h"
11
12
13 //**********************************************************************************************************************
14 vector<string> SetLogFileCommand::setParameters(){      
15         try {
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);
20                 
21                 vector<string> myArray;
22                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
23                 return myArray;
24         }
25         catch(exception& e) {
26                 m->errorOut(e, "SetLogFileCommand", "setParameters");
27                 exit(1);
28         }
29 }
30 //**********************************************************************************************************************
31 string SetLogFileCommand::getHelpString(){      
32         try {
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";
39                 return helpString;
40         }
41         catch(exception& e) {
42                 m->errorOut(e, "SetLogFileCommand", "getHelpString");
43                 exit(1);
44         }
45 }
46 //**********************************************************************************************************************
47
48 SetLogFileCommand::SetLogFileCommand(string option)  {
49         try {
50                 abort = false; calledHelp = false;   
51                 
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;}
55                 
56                 else {
57                         vector<string> myArray = setParameters();
58                         
59                         OptionParser parser(option);
60                         map<string, string> parameters = parser.getParameters();
61                         
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;  }
66                         }
67                 
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; } 
70                         
71                         string temp = validParameter.validFile(parameters, "append", false);            if (temp == "not found") {  temp = "F";  }
72                         append = m->isTrue(temp);
73                 }
74         }
75         catch(exception& e) {
76                 m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
77                 exit(1);
78         }
79 }
80
81 //**********************************************************************************************************************
82
83 int SetLogFileCommand::execute(){
84         try {
85                 
86                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
87                 
88                 commandFactory = CommandFactory::getInstance();
89                 
90                 commandFactory->setLogfileName(name, append);
91                 
92                 return 0;
93         }
94         catch(exception& e) {
95                 m->errorOut(e, "SetLogFileCommand", "execute");
96                 exit(1);
97         }
98 }
99 //**********************************************************************************************************************/