#include "configuration.h" #include <string> #include <iostream> #include <algorithm> using namespace std; class Exec { protected: std::string _command; bool _executed; bool _verbose; public: Exec(const std::string& command, bool verbose = false) : _command(command), _executed(false), _verbose(verbose) { } void operator()(Executable * exec) { if (_verbose) { std::cout << "Executing : " << *exec << std::endl; } exec->executeCommand(_command); } bool hasExecuted() const { return _executed; } }; class ExecIfName : public Exec { private: std::string _name; public: ExecIfName(const std::string& command, const std::string& name, bool verbose = false) : Exec(command, verbose), _name(name) { } void operator()(Executable * exec) { if (exec->getName() == _name) { if (_verbose) { std::cout << "Executing : " << *exec << std::endl; } exec->executeCommand(_command); _executed = true; } } }; class ExecIfType : public Exec { private: std::string _type; public: ExecIfType(const std::string& command, const std::string& type, bool verbose = false) : Exec(command, verbose), _type(type) { } void operator()(Executable * exec) { if (exec->getType() == _type) { if (_verbose) { std::cout << "Executing : " << *exec << std::endl; } exec->executeCommand(_command); _executed = true; } } }; class ExecIfTypeAndName : public Exec { private: std::string _type; std::string _name; public: ExecIfTypeAndName(const std::string& command, const std::string& type, const std::string& name, bool verbose = false) : Exec(command, verbose), _type(type), _name(name) { } void operator()(Executable * exec) { if (exec->getType() == _type && exec->getName() == _name) { if (_verbose) { std::cout << "Executing : " << *exec << std::endl; } exec->executeCommand(_command); _executed = true; } } }; void Configuration::addVariable(const std::string& name, const std::string& value) { _globalEnvironment[name] = value; } void Configuration::addExecutable(Executable * executable) { _servers.push_back(executable); if (_verbose) { std::cout << "found server : " << *executable << std::endl; } } void Configuration::reverseServerOrder() { reverse(_servers.begin(), _servers.end()); } bool Configuration::execAll(const std::string& command) { Exec exec(command, _verbose); for_each(_servers.begin(), _servers.end(), exec); return exec.hasExecuted(); } bool Configuration::execIfName(const std::string& command, const std::string& name) { ExecIfName exec(command, name, _verbose); for_each(_servers.begin(), _servers.end(), exec); return exec.hasExecuted(); } bool Configuration::execIfType(const std::string& command, const std::string& type) { ExecIfType exec(command, type, _verbose); for_each(_servers.begin(), _servers.end(), exec); return exec.hasExecuted(); } bool Configuration::execIfTypeAndName(const std::string& command, const std::string& type, const std::string& name) { ExecIfTypeAndName exec(command, type, name, _verbose); for_each(_servers.begin(), _servers.end(), exec); return exec.hasExecuted(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 6307 | Sven Erik Knop |
Several updates. Each command now accepts an "Options" variable for miscellaneous parameters for the executables that have no equivalent environment variable. For example, p4web has the option -b or -B, which can only be invoked on the command line. Updated documentation as well. |
||
#2 | 5987 | Sven Erik Knop |
Few minor changes: All commands now accept variable called "Options". This can be used to collect all options for which Perforce has not defined an environment variable - for example the undocumented "-C1" for p4d to start a case insensitive server. p4d also accepts the variables P4USER and P4PASSWD. These are only used for stopping the service, which is done first via "p4 admin stop". Note that if the stop via the admin command fails, p4dcfg will stop the service via a kill |
||
#1 | 5882 | Sven Erik Knop | initial publish |