/* * Copyright 2014 Range Networks, Inc. * * This software is distributed under multiple licenses; * see the COPYING file in the main directory for licensing * information for this specific distribution. * * This use of this software may be subject to additional restrictions. * See the LEGAL file in the main directory for details. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include #include "CLI.h" namespace CommandLine { /** Print or modify the global configuration table. */ CLIStatus configCmd(string mode, int argc, char** argv, ostream& os) { // no args, just print if (argc==1) { ConfigurationKeyMap::iterator mp = gConfig.mSchema.begin(); while (mp != gConfig.mSchema.end()) { if (mode.compare("customer") == 0) { if (mp->second.getVisibility() == ConfigurationKey::CUSTOMER || mp->second.getVisibility() == ConfigurationKey::CUSTOMERSITE || mp->second.getVisibility() == ConfigurationKey::CUSTOMERTUNE || mp->second.getVisibility() == ConfigurationKey::CUSTOMERWARN) { ConfigurationKey::printKey(mp->second, gConfig.getStr(mp->first), os); } } else if (mode.compare("developer") == 0) { ConfigurationKey::printKey(mp->second, gConfig.getStr(mp->first), os); } mp++; } return SUCCESS; } // one arg if (argc==2) { // matches exactly? print single key if (gConfig.keyDefinedInSchema(argv[1])) { ConfigurationKey::printKey(gConfig.mSchema[argv[1]], gConfig.getStr(argv[1]), os); ConfigurationKey::printDescription(gConfig.mSchema[argv[1]], os); os << endl; // ...otherwise print all similar keys } else { int foundCount = 0; ConfigurationKeyMap matches = gConfig.getSimilarKeys(argv[1]); ConfigurationKeyMap::iterator mp = matches.begin(); while (mp != matches.end()) { if (mode.compare("customer") == 0) { if (mp->second.getVisibility() == ConfigurationKey::CUSTOMER || mp->second.getVisibility() == ConfigurationKey::CUSTOMERSITE || mp->second.getVisibility() == ConfigurationKey::CUSTOMERTUNE || mp->second.getVisibility() == ConfigurationKey::CUSTOMERWARN) { ConfigurationKey::printKey(mp->second, gConfig.getStr(mp->first), os); foundCount++; } } else if (mode.compare("developer") == 0) { ConfigurationKey::printKey(mp->second, gConfig.getStr(mp->first), os); foundCount++; } mp++; } if (!foundCount) { os << argv[1] << " - no keys matched"; if (mode.compare("customer") == 0) { os << ", developer/factory keys can be accessed with \"devconfig\"."; } else if (mode.compare("developer") == 0) { os << ", custom keys can be accessed with \"rawconfig\"."; } os << endl; } } return SUCCESS; } // >1 args: set new value string val; for (int i=2; i warnings = gConfig.crossCheck(argv[1]); vector::iterator warning = warnings.begin(); while (warning != warnings.end()) { os << "WARNING: " << *warning << endl; warning++; } if (gConfig.isStatic(argv[1])) { os << argv[1] << " is static; change takes effect on restart" << endl; } return SUCCESS; } if (!gConfig.remove(argv[1])) { os << "DB ERROR: " << argv[1] << " could not be removed from the configuration table" << endl; return FAILURE; } os << argv[1] << " removed from the configuration table" << endl; return SUCCESS; } /** Print or modify the global configuration table. */ CLIStatus rawconfig(int argc, char** argv, ostream& os) { // no args, just print if (argc==1) { gConfig.find("",os); return SUCCESS; } // one arg, pattern match and print if (argc==2) { gConfig.find(argv[1],os); return SUCCESS; } // >1 args: set new value string val; for (int i=2; i