Created
October 13, 2018 02:45
-
-
Save ndugger/5d8c5b020a13b88c9a4800363b94245b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # include <functional> | |
| # include <map> | |
| # include <regex> | |
| # include <string> | |
| # include <vector> | |
| # include "grok/commands/help.h" | |
| # include "grok/commands/make.h" | |
| # include "grok/commands/sync.h" | |
| # include "grok/commands/update.h" | |
| # include "grok/commands/use.h" | |
| # include "grok/core/unrecognized.h" | |
| using std::function; | |
| using std::map; | |
| using std::regex; | |
| using std::regex_replace; | |
| using std::string; | |
| using std::vector; | |
| using namespace grok; | |
| namespace grok { | |
| typedef function<int(string, vector<string>, bool)> command; | |
| map<string, command> command_map = { | |
| { "help", commands::help }, | |
| { "make", commands::make }, | |
| { "sync", commands::sync }, | |
| { "update", commands::update }, | |
| { "use", commands::use } | |
| }; | |
| } | |
| int main (int count, char* arguments[]) { | |
| string command_from = regex_replace(arguments[ 0 ], regex("/grok$"), ""); | |
| if (count <= 1) { | |
| return commands::help(command_from, { }); | |
| } | |
| string command_name = arguments[ 1 ]; | |
| vector<string> command_arguments; | |
| for (int i = 0; i < count - 2; ++i) { | |
| command_arguments.emplace_back(arguments[ i + 2 ]); | |
| } | |
| bool command_by_user = true; | |
| if (command_map[ command_name ] == nullptr) { | |
| return core::unrecognized(command_name); | |
| } | |
| else { | |
| return command_map[ command_name ](command_from, command_arguments, command_by_user); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment