#include "CmdRegistry.h" #include "ICmd.h" #include #include #include #include #include namespace bts { namespace cmd { std::map> CmdRegistry::_cmds; int CmdRegistry::dispatch (int argc, char **argv) { if (argc < 2) return _cmds["help"]->execute (std::vector ()); else { std::vector args; for (int i = 1; i < argc; i++) { std::string arg (argv[i]); if (boost::starts_with(boost::to_lower_copy(arg),"-configserver")) { // skip configserver flag as well as url i++; } else args.push_back (arg); } ICmd *cmd = retrieve (std::string (args[0])); if (cmd == 0) { return _cmds["help"]->execute(std::vector()); } else { args.erase (args.begin ()); return cmd->execute (args); } } } ICmd * CmdRegistry::retrieve (std::string const &name) { std::string lname (name); boost::to_lower (lname); if (_cmds.find (lname) == _cmds.end ()) return 0; else return _cmds[lname].get (); } std::vector CmdRegistry::cmds () { std::vector result; for (auto&p : _cmds) result.push_back (p.first); return result; } }}