00001 #ifdef TEST
00002 #include "headers.h"
00003
00004 static const string configureCommandString = "config";
00005 static const string readCommandString = "read";
00006 static const string writeCommandString = "write";
00007
00008 void
00009 ConfigureCommand::getHtmlInterface(std::ostream& s) {
00010 s << "<h2>Configure</h2>";
00011 generateHtmlCmd(s, "(help)");
00012 beginUl(s);
00013 generateHtmlSubcmd(s, showCommandString, "show");
00014 generateHtmlSubcmdArg1(s, readCommandString, "Read from config file: ", "Read");
00015 generateHtmlSubcmdArg1(s, writeCommandString, "Write to config file: ", "Write");
00016 s << " <li><form action=\"/\" method=get>"
00017 << "<input type=hidden name=cmd value=" << getCommandString() << ">"
00018 << "Variable name: "
00019 << "<input type=text name=variableName>"
00020 << " Value: "
00021 << "<input type=text name=value>"
00022 << " <input type=submit value=Set></form>\n";
00023 endUl(s);
00024 }
00025
00026
00027 string
00028 ConfigureCommand::getCommandString() {
00029 return configureCommandString;
00030 }
00031
00032
00036 void
00037 ConfigureCommand::run(std::ostream& s)
00038 {
00039 if (m_args[1].empty()) {
00040 getHelp(s);
00041 return;
00042 }
00043
00044 if(m_args[1] == readCommandString)
00045 {
00046 if (m_args[2].empty()) {
00047 m_args[2] = DEFAULT_CONFIG_FILE;
00048 }
00049 if (GlobalObjects::instance()->getConfig()->load(m_args[2])) {
00050 s << "Reading config from \"" << m_args[2] << "\" succeeded";
00051 return;
00052 }
00053 else {
00054 s << "Reading config from \"" << m_args[2] << "\" failed!";
00055 return;
00056 }
00057 }
00058 else if(m_args[1] == writeCommandString) {
00059 if (m_args[2].empty()) {
00060 m_args[2] = DEFAULT_CONFIG_FILE;
00061 }
00062 if (GlobalObjects::instance()->getConfig()->save(m_args[2])) {
00063 s << "Writing config to \"" << m_args[2] << "\" succeeded";
00064 return;
00065 }
00066 else {
00067 s << "Writing config to \"" << m_args[2] << "\" failed!";
00068 return;
00069 }
00070 }
00071 else if(m_args[1] == showCommandString) {
00072 s << GlobalObjects::instance()->getConfig()->toString();
00073 return;
00074 }
00075 else if(!GlobalObjects::instance()->getConfig()->set(m_args[1], m_args[2])) {
00076 getHelp(s);
00077 return;
00078 }
00079
00080 s << "Variable set successfully.";
00081 }
00082
00083
00084 void
00085 ConfigureCommand::getHelp(std::ostream& s) {
00086 s << "Syntax: "
00087 << configureCommandString << " [SUBCOMMAND] [ARG] -- subcommands:\n"
00088 << " " << showCommandString << "\n"
00089 << " " << writeCommandString << " - write configuration to disk\n"
00090 << " Arguments: FILE_NAME (Default: " << DEFAULT_CONFIG_FILE << ")\n"
00091 << " " << readCommandString << " - read configuration from disk\n"
00092 << " Arguments: FILE_NAME (Default: " << DEFAULT_CONFIG_FILE << ")\n\n"
00093 << configureCommandString << " <variable> <value> -- variables:\n";
00094 GlobalObjects::instance()->getConfig()->getHelpForVariables(s);
00095 }
00096
00097
00098 #endif
00099