diff --git a/include/cellar.hpp b/include/cellar.hpp index 1b7774f..511c4b9 100644 --- a/include/cellar.hpp +++ b/include/cellar.hpp @@ -1,9 +1,14 @@ #ifndef __CELLAR_HPP #define __CELLAR_HPP #pragma once +#include +#include + +using namespace std; namespace cellar { - void print_header(); + extern void print_header(); + extern void print_version(int,vector); } #endif // __CELLAR_HPP diff --git a/include/commands.hpp b/include/commands.hpp index 482b8be..7fa169e 100644 --- a/include/commands.hpp +++ b/include/commands.hpp @@ -14,6 +14,8 @@ namespace cellar { void add_command(string, CommandFunction); vector list_commands(); + + extern map core_commands(); } } diff --git a/src/cellar.cpp b/src/cellar.cpp.cog similarity index 80% rename from src/cellar.cpp rename to src/cellar.cpp.cog index 5947eab..7042e80 100644 --- a/src/cellar.cpp +++ b/src/cellar.cpp.cog @@ -1,3 +1,4 @@ +// vim: filetype=cpp #include #include #include @@ -42,9 +43,18 @@ int main(int argc, char* argv[]) { cmdparse.parse(argc, argv); - for (auto item : commands::bottles_commands()) { - commands::command_map[item.first] = item.second; - } + /*[[[cog + import cog + + with open("src/modules.txt") as modules: + for module in modules: + cog.out(""" + for (auto item : commands::""" + module.strip() + """_commands()) { + commands::command_map[item.first] = item.second; + } + """, dedent=True, trimblanklines=True) + ]]]*/ + //[[[end]]] string usercmd = command.getValue(); if (commands::command_map.count(usercmd) > 0) { diff --git a/src/commands.cpp b/src/commands.cpp.cog similarity index 61% rename from src/commands.cpp rename to src/commands.cpp.cog index 1f2865d..ef68830 100644 --- a/src/commands.cpp +++ b/src/commands.cpp.cog @@ -1,3 +1,4 @@ +// vim: filetype=cpp : #include #include #include @@ -37,4 +38,20 @@ void help_command(int argc, vector argv) { } cout << endl; } -CommandFunction helpcmd = command_map["help"] = &help_command; + +map cellar::commands::core_commands() { + map result; + /*[[[cog + import cog + + with open("src/commands.txt") as commandfile: + for line in commandfile: + linesplit = line.strip().split(" ") + name = linesplit[0] + func = linesplit[1] + + cog.outl("result.insert(pair(\"{0}\", &{1}));".format(name, func)) + ]]]*/ + //[[[end]]] + return result; +} diff --git a/src/commands.txt b/src/commands.txt new file mode 100644 index 0000000..da23819 --- /dev/null +++ b/src/commands.txt @@ -0,0 +1,2 @@ +version print_version +help help_command diff --git a/src/modules.txt b/src/modules.txt new file mode 100644 index 0000000..3a422f6 --- /dev/null +++ b/src/modules.txt @@ -0,0 +1,2 @@ +core +bottles diff --git a/src/version.cpp.cog b/src/version.cpp.cog index 4820a07..1750e02 100644 --- a/src/version.cpp.cog +++ b/src/version.cpp.cog @@ -3,6 +3,7 @@ #include #include +#include "cellar.hpp" #include "commands.hpp" #include "output.hpp" #include "version.hpp" @@ -41,7 +42,6 @@ string cellar::version::short_version() { //[[[end]]] } -void print_version(int argc, vector argv) { +void cellar::print_version(int argc, vector argv) { cellar::output::statement(short_version()); } -cellar::commands::CommandFunction versioncmd = cellar::commands::command_map["version"] = &print_version;