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