Skip to content

Instantly share code, notes, and snippets.

@ndugger
Last active October 8, 2018 18:06
Show Gist options
  • Save ndugger/9ce623bcc41be9888264e096c51061ee to your computer and use it in GitHub Desktop.
Save ndugger/9ce623bcc41be9888264e096c51061ee to your computer and use it in GitHub Desktop.
# include <functional>
# include <iostream>
# include <map>
# include <string>
# include "git2/global.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/utilities/unrecognized.h"
using namespace std;
using namespace grok::commands;
using namespace grok::utilities;
map<string, function<int(string[])>> commands = {
{ "help", help },
{ "make", make },
{ "sync", sync },
{ "update", update },
{ "use", use }
};
int main (int size, char* arguments[]) {
string command_name = arguments[ 1 ];
string command_arguments[ size - 2 ];
for (int i = 0; i < size - 2; ++i) {
command_arguments[ i ] = arguments[ i + 2 ];
}
git_libgit2_init();
if (size < 2) {
return help(command_arguments);
}
else if (commands[ command_name ] == nullptr) {
return unrecognized(command_name);
}
else {
return commands[ command_name ](command_arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment