]> git.donarmstrong.com Git - mothur.git/blob - setlogfilecommand.cpp
f57dfafeacd9caae5711f56c17c3102e083567f0
[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 vector<string> SetLogFileCommand::getValidParameters(){ 
14         try {
15                 string Array[] =  {"name","append","outputdir","inputdir"};
16                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
17                 return myArray;
18         }
19         catch(exception& e) {
20                 m->errorOut(e, "SetLogFileCommand", "getValidParameters");
21                 exit(1);
22         }
23 }
24 //**********************************************************************************************************************
25 vector<string> SetLogFileCommand::getRequiredParameters(){      
26         try {
27                 string Array[] =  {"name"};
28                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
29                 return myArray;
30         }
31         catch(exception& e) {
32                 m->errorOut(e, "SetLogFileCommand", "getRequiredParameters");
33                 exit(1);
34         }
35 }
36 //**********************************************************************************************************************
37 vector<string> SetLogFileCommand::getRequiredFiles(){   
38         try {
39                 vector<string> myArray;
40                 return myArray;
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "SetLogFileCommand", "getRequiredFiles");
44                 exit(1);
45         }
46 }
47 //**********************************************************************************************************************
48
49 SetLogFileCommand::SetLogFileCommand(string option)  {
50         try {
51                 abort = false; calledHelp = false;   
52                 
53                 //allow user to run help
54                 if(option == "help") { help(); abort = true; calledHelp = true; }
55                 
56                 else {
57                         //valid paramters for this command
58                         string Array[] =  {"name","append","outputdir","inputdir"};
59                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
60                         
61                         OptionParser parser(option);
62                         map<string, string> parameters = parser.getParameters();
63                         
64                         ValidParameters validParameter;
65                         //check to make sure all parameters are valid for command
66                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
67                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
68                         }
69                 
70                         name = validParameter.validFile(parameters, "name", false);                     
71                         if (name == "not found") {  m->mothurOut("name is a required parameter for the set.logfile command."); abort = true; } 
72                         
73                         string temp = validParameter.validFile(parameters, "append", false);            if (temp == "not found") {  temp = "F";  }
74                         append = m->isTrue(temp);
75                 }
76         }
77         catch(exception& e) {
78                 m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
79                 exit(1);
80         }
81 }
82 //**********************************************************************************************************************
83
84 void SetLogFileCommand::help(){
85         try {
86                 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");
87                 m->mothurOut("The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n");
88                 m->mothurOut("The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n");
89                 m->mothurOut("Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n");
90                 m->mothurOut("Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n\n");
91         }
92         catch(exception& e) {
93                 m->errorOut(e, "SetLogFileCommand", "help");
94                 exit(1);
95         }
96 }
97 //**********************************************************************************************************************
98
99 SetLogFileCommand::~SetLogFileCommand(){}
100
101 //**********************************************************************************************************************
102
103 int SetLogFileCommand::execute(){
104         try {
105                 
106                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
107                 
108                 commandFactory = CommandFactory::getInstance();
109                 
110                 commandFactory->setLogfileName(name, append);
111                 
112                 return 0;
113         }
114         catch(exception& e) {
115                 m->errorOut(e, "SetLogFileCommand", "execute");
116                 exit(1);
117         }
118 }
119 //**********************************************************************************************************************/