Massive reformating and cleanup
This commit is contained in:
@ -3,51 +3,41 @@
|
||||
#include <unordered_map>
|
||||
|
||||
#include "cmd/cmd_base.hpp"
|
||||
#include "cmd/cmd_wc.hpp"
|
||||
#include "cmd/cmd_time.hpp"
|
||||
#include "cmd/cmd_date.hpp"
|
||||
#include "cmd/cmd_echo.hpp"
|
||||
#include "cmd/cmd_touch.hpp"
|
||||
#include "cmd/cmd_misc.hpp"
|
||||
#include "cmd/cmd_time.hpp"
|
||||
#include "cmd/cmd_touch.hpp"
|
||||
#include "cmd/cmd_wc.hpp"
|
||||
|
||||
namespace fsh
|
||||
{
|
||||
namespace fsh {
|
||||
|
||||
class CommandRegistry {
|
||||
|
||||
public:
|
||||
|
||||
static CommandRegistry& instance() {
|
||||
static CommandRegistry cmd_registry;
|
||||
return cmd_registry;
|
||||
}
|
||||
|
||||
Command& get(const std::string n) {
|
||||
if(cmds.find(n) == cmds.end()) {
|
||||
throw std::runtime_error("Command not found");
|
||||
class CommandRegistry {
|
||||
public:
|
||||
static CommandRegistry& instance() {
|
||||
static CommandRegistry cmd_registry;
|
||||
return cmd_registry;
|
||||
}
|
||||
return *(cmds[n]);
|
||||
}
|
||||
|
||||
Command& operator[](const std::string n) {
|
||||
return get(n);
|
||||
}
|
||||
Command& get(const std::string n) {
|
||||
if (cmds.find(n) == cmds.end()) { throw std::runtime_error("Command not found"); }
|
||||
return *(cmds[n]);
|
||||
}
|
||||
|
||||
Command& operator[](const std::string n) { return get(n); }
|
||||
|
||||
private:
|
||||
CommandRegistry() {
|
||||
cmds["wc" ] = Command::register_cmd<CmdWc>();
|
||||
cmds["date" ] = Command::register_cmd<CmdDate>();
|
||||
cmds["time" ] = Command::register_cmd<CmdTime>();
|
||||
cmds["echo" ] = Command::register_cmd<CmdEcho>();
|
||||
cmds["exit" ] = Command::register_cmd<CmdExit>();
|
||||
cmds["touch"] = Command::register_cmd<CmdTouch>();
|
||||
cmds["debug"] = Command::register_cmd<CmdPrintTree>();
|
||||
}
|
||||
private:
|
||||
CommandRegistry() {
|
||||
cmds["wc"] = Command::register_cmd<CmdWc>();
|
||||
cmds["date"] = Command::register_cmd<CmdDate>();
|
||||
cmds["time"] = Command::register_cmd<CmdTime>();
|
||||
cmds["echo"] = Command::register_cmd<CmdEcho>();
|
||||
cmds["exit"] = Command::register_cmd<CmdExit>();
|
||||
cmds["touch"] = Command::register_cmd<CmdTouch>();
|
||||
cmds["debug"] = Command::register_cmd<CmdPrintTree>();
|
||||
}
|
||||
|
||||
std::unordered_map<std::string, std::unique_ptr<Command> > cmds;
|
||||
std::unordered_map<std::string, std::unique_ptr<Command> > cmds;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace fsh
|
||||
Reference in New Issue
Block a user