2 * setlogfilecommand.cpp
5 * Created by westcott on 4/27/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "setlogfilecommand.h"
12 //**********************************************************************************************************************
13 vector<string> SetLogFileCommand::getValidParameters(){
15 string Array[] = {"name","append","outputdir","inputdir"};
16 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
20 m->errorOut(e, "SetLogFileCommand", "getValidParameters");
24 //**********************************************************************************************************************
25 vector<string> SetLogFileCommand::getRequiredParameters(){
27 string Array[] = {"name"};
28 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
32 m->errorOut(e, "SetLogFileCommand", "getRequiredParameters");
36 //**********************************************************************************************************************
37 vector<string> SetLogFileCommand::getRequiredFiles(){
39 vector<string> myArray;
43 m->errorOut(e, "SetLogFileCommand", "getRequiredFiles");
47 //**********************************************************************************************************************
49 SetLogFileCommand::SetLogFileCommand(string option) {
53 //allow user to run help
54 if(option == "help") { help(); abort = true; }
57 //valid paramters for this command
58 string Array[] = {"name","append","outputdir","inputdir"};
59 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
61 OptionParser parser(option);
62 map<string, string> parameters = parser.getParameters();
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; }
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; }
73 string temp = validParameter.validFile(parameters, "append", false); if (temp == "not found") { temp = "F"; }
74 append = m->isTrue(temp);
78 m->errorOut(e, "SetLogFileCommand", "SetLogFileCommand");
82 //**********************************************************************************************************************
84 void SetLogFileCommand::help(){
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");
93 m->errorOut(e, "SetLogFileCommand", "help");
97 //**********************************************************************************************************************
99 SetLogFileCommand::~SetLogFileCommand(){}
101 //**********************************************************************************************************************
103 int SetLogFileCommand::execute(){
106 if (abort == true) { return 0; }
108 commandFactory = CommandFactory::getInstance();
110 commandFactory->setLogfileName(name, append);
114 catch(exception& e) {
115 m->errorOut(e, "SetLogFileCommand", "execute");
119 //**********************************************************************************************************************/