]> git.donarmstrong.com Git - mothur.git/blobdiff - setlogfilecommand.cpp
added set.logfile command
[mothur.git] / setlogfilecommand.cpp
diff --git a/setlogfilecommand.cpp b/setlogfilecommand.cpp
new file mode 100644 (file)
index 0000000..593664e
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ *  setlogfilecommand.cpp
+ *  Mothur
+ *
+ *  Created by westcott on 4/27/10.
+ *  Copyright 2010 Schloss Lab. All rights reserved.
+ *
+ */
+
+#include "setlogfilecommand.h"
+
+//**********************************************************************************************************************
+
+SetLogFileCommand::SetLogFileCommand(string option)  {
+       try {
+               abort = false;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
+               
+               else {
+                       //valid paramters for this command
+                       string Array[] =  {"name","append","outputdir","inputdir"};
+                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       
+                       OptionParser parser(option);
+                       map<string, string> parameters = parser.getParameters();
+                       
+                       ValidParameters validParameter;
+                       //check to make sure all parameters are valid for command
+                       for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                               if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
+                       }
+               
+                       name = validParameter.validFile(parameters, "name", false);                     
+                       if (name == "not found") {  m->mothurOut("name is a required parameter for the set.logfile command."); abort = true; } 
+                       
+                       string temp = validParameter.validFile(parameters, "append", false);            if (temp == "not found") {  temp = "F";  }
+                       append = isTrue(temp);
+               }
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+void SetLogFileCommand::help(){
+       try {
+               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");
+               m->mothurOut("The set.logfile command parameters are name and append, name is required. Append is set to false by default.\n");
+               m->mothurOut("The set.logfile command should be in the following format: set.logfile(name=yourLogFileName, append=T).\n");
+               m->mothurOut("Example set.logfile(name=/Users/lab/desktop/output.txt, append=T).\n");
+               m->mothurOut("Note: No spaces between parameter labels (i.e. name), '=' and parameters (i.e.yourLogFileName).\n\n");
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SetLogFileCommand", "help");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+
+SetLogFileCommand::~SetLogFileCommand(){}
+
+//**********************************************************************************************************************
+
+int SetLogFileCommand::execute(){
+       try {
+               
+               if (abort == true) { return 0; }
+               
+               commandFactory = CommandFactory::getInstance();
+               
+               commandFactory->setLogfileName(name, append);
+               
+               return 0;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SetLogFileCommand", "execute");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************/