so that's how libraries work

This commit is contained in:
Nicholas O'Connor
2017-03-23 12:06:29 -07:00
parent 64c96cba26
commit 30d0787a62
5 changed files with 45 additions and 5 deletions

View File

@@ -11,11 +11,13 @@
#include "bottles.hpp"
#include "commands.hpp"
#include "dll.hpp"
#include "fs.hpp"
using namespace std;
using namespace cellar::bottles;
using CommandFunction = cellar::commands::CommandFunction;
using json = nlohmann::json;
Bottle::Bottle() {
@@ -25,7 +27,7 @@ Bottle::Bottle() {
type = bottle_anonymous;
}
map<string, Bottle> cellar::bottles::get_bottles() {
DLL_PUBLIC map<string, Bottle> cellar::bottles::get_bottles() {
map<string, Bottle> result;
string homepath = getenv("HOME");
@@ -95,4 +97,8 @@ void print_bottles(int argc, char** argv) {
cout << endl;
}
}
cellar::commands::CommandFunction listcmd = cellar::commands::command_map["list"] = &print_bottles;
DLL_PUBLIC map<string, CommandFunction> cellar::commands::bottles_commands() {
map<string, CommandFunction> result;
result.insert(pair<string,CommandFunction>("list", &print_bottles));
return result;
}

View File

@@ -37,6 +37,10 @@ int main(int argc, char* argv[]) {
cmdparse.parse(argc, argv);
for (auto item : commands::bottles_commands()) {
commands::command_map[item.first] = item.second;
}
string usercmd = command.getValue();
if (commands::command_map.count(usercmd) > 0) {
commands::command_map[usercmd](argc, argv);