]> git.donarmstrong.com Git - mothur.git/blob - setlogfilecommand.cpp
0a3dfc974f1d6ca45352b712efea37a2df02daf0
[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); 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                 
55                 else {
56                         //valid paramters for this command
57                         string Array[] =  {"name","append","outputdir","inputdir"};
58                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
59                         
60                         OptionParser parser(option);
61                         map<string, string> parameters = parser.getParameters();
62                         
63                         ValidParameters validParameter;
64                         //check to make sure all parameters are valid for command
65                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
66                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
67                         }
68                 
69                         name = validParameter.validFile(parameters, "name", false);                     
70                         if (name == "not found") {  m->mothurOut("name is a required parameter for the set.logfile command."); abort = true; } 
71                         
72                         string temp = validParameter.validFile(parameters, "append", false);            if (temp == "not found") {  temp = "F";  }
73                         append = m->isTrue(temp);
74                 }
75         }
76         catch(exception& e) {
77                 m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
78                 exit(1);
79         }
80 }
81
82 //**********************************************************************************************************************
83
84 int SetLogFileCommand::execute(){
85         try {
86                 
87                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
88                 
89                 commandFactory = CommandFactory::getInstance();
90                 
91                 commandFactory->setLogfileName(name, append);
92                 
93                 return 0;
94         }
95         catch(exception& e) {
96                 m->errorOut(e, "SetLogFileCommand", "execute");
97                 exit(1);
98         }
99 }
100 //**********************************************************************************************************************/