Created
October 14, 2018 15:58
-
-
Save ndugger/196fb0cdd7866239e8c062a0c254c9ee 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/apply.h" | |
| # 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" | |
| namespace grok { | |
| using std::function; | |
| using std::map; | |
| using std::regex; | |
| using std::regex_replace; | |
| using std::string; | |
| using std::vector; | |
| typedef function<int(string, vector<string>, bool)> command; | |
| map<string, command> command_map = { | |
| { "apply", commands::apply }, | |
| { "help", commands::help }, | |
| { "make", commands::make }, | |
| { "sync", commands::sync }, | |
| { "update", commands::update }, | |
| { "use", commands::use } | |
| }; | |
| int execute (vector<string> arguments) { | |
| string command_binary_location = regex_replace(arguments[ 0 ], regex("/grok$"), ""); | |
| bool command_by_user = true; | |
| if (arguments.size() <= 1) { | |
| return commands::help(command_binary_location, { }, command_by_user); | |
| } | |
| string command_name = arguments[ 1 ]; | |
| vector<string> command_arguments; | |
| for (int i = 0; i < arguments.size() - 2; ++i) { | |
| command_arguments.emplace_back(arguments[ i + 2 ]); | |
| } | |
| if (command_map[ command_name ] == nullptr) { | |
| return core::unrecognized(command_name); | |
| } | |
| else { | |
| return command_map[ command_name ](command_binary_location, command_arguments, command_by_user); | |
| } | |
| } | |
| } | |
| int main (int arg_c, char* arg_v[ ]) { | |
| return grok::execute(std::vector<std::string>(arg_v, arg_v + arg_c)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment