diff --git a/src/Makefile.am b/src/Makefile.am index 860f0f0..569b6cc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ bin_PROGRAMS = cellar cellar_CPPFLAGS = $(BOOST_CPPFLAGS) cellar_LDFLAGS = $(BOOST_LDFLAGS) $(BOOST_SYSTEM_LIB) $(BOOST_FILESYSTEM_LIB) -cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp +cellar_SOURCES = cellar.cpp fs.cpp bottles.cpp commands.cpp diff --git a/src/cellar.cpp b/src/cellar.cpp index bd03324..2aa373a 100644 --- a/src/cellar.cpp +++ b/src/cellar.cpp @@ -6,34 +6,17 @@ #include "json.hpp" #include "bottles.hpp" +#include "commands.hpp" using namespace std; using namespace cellar; using json = nlohmann::json; int main(int argc, char* argv[]) { - map bottles = bottles::get_bottles(); - for (auto& item : bottles) { - cout << item.first << "- "; - bottles::Bottle current = item.second; - - switch (current.type) { - case bottles::bottle_anonymous: - cout << "anonymous wine bottle"; - break; - case bottles::bottle_labelled: - cout << current.config["name"]; - break; - case bottles::bottle_symlink: - cout << "symlink to "; - cout << current.canonical_path; - break; - default: - cout << "broken or unsupported wine bottle"; - } - - cout << endl; - } - - return 0; + vector commands = commands::list_commands(); + cout << "cellar - bottle management tool for WINE connoisseurs" << std::endl; + for (string item : commands) { + cout << item << " has loaded" << endl; + } + return 0; } diff --git a/src/commands.cpp b/src/commands.cpp new file mode 100644 index 0000000..dc04315 --- /dev/null +++ b/src/commands.cpp @@ -0,0 +1,19 @@ +#include "commands.hpp" + +using namespace std; +using namespace cellar::commands; + +map cellar::commands::command_map; + +bool cellar::commands::add_command(string name, CommandFunction func) { + command_map[name] = func; + return true; +} + +vector cellar::commands::list_commands() { + vector result; + for (auto& item : command_map) { + result.push_back(item.first); + } + return result; +} diff --git a/src/commands.hpp b/src/commands.hpp new file mode 100644 index 0000000..29a7b55 --- /dev/null +++ b/src/commands.hpp @@ -0,0 +1,20 @@ +#ifndef __COMMANDS_HPP +#define __COMMANDS_HPP +#pragma once + +#include +#include +#include + +using namespace std; +namespace cellar { + namespace commands { + typedef void (*CommandFunction)(int, char*[]); + extern map command_map; + + bool add_command(string, CommandFunction); + vector list_commands(); + } +} + +#endif // __COMMANDS_HPP