diff --git a/include/internal/core.hpp.cog b/include/internal/core.hpp.cog index 1549e9d..0a87a5c 100644 --- a/include/internal/core.hpp.cog +++ b/include/internal/core.hpp.cog @@ -11,16 +11,18 @@ using namespace cellar::commands; namespace cellar { - namespace commands { + namespace core { /*[[[cog import cog - with open("src/commands.txt") as commandsfile: + with open("src/core/commands.txt") as commandsfile: for line in commandsfile: item = line.strip().split(" ") cog.outl("extern void {0} (int, vector);".format(item[1])) ]]]*/ //[[[end]]] + } + namespace commands { extern map core_commands(); } } diff --git a/src/bottles/commands.cpp.cog b/src/bottles/commands.cpp.cog deleted file mode 100644 index b0e0204..0000000 --- a/src/bottles/commands.cpp.cog +++ /dev/null @@ -1,48 +0,0 @@ -// vim: filetype=cpp : -#include - -#include "bottles.hpp" -#include "internal/bottles.hpp" -#include "commands.hpp" -#include "help.hpp" - -using namespace std; -using namespace cellar::bottles; -using namespace cellar::commands; - -map cellar::commands::bottles_commands() { - map result; -/*[[[cog - import cog - import os - - with open("src/bottles/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)) - - if (len(linesplit) > 2): - desc = " ".join(linesplit[2:]) # Rest of line assumed to be description - cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" - .format(name, desc - .replace("\\", "\\\\") - .replace("\"", "\\\""))) - # the replace methods escape " and \ characters - else: - print("-- No description is available for the {0} command.".format(name)) - - if os.path.exists("src/bottles/help/" + name): - cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) - with open("src/bottles/help/" + name) as detailsfile: - for detail in detailsfile: - cog.out(detail, trimblanklines=True) - cog.out(")\");") - else: - print("-- No details are available for the {0} command.".format(name)) - ]]]*/ -//[[[end]]] - return result; -} diff --git a/src/commands.cpp.cog b/src/commands.cpp.cog index 21fa6bf..338b3ea 100644 --- a/src/commands.cpp.cog +++ b/src/commands.cpp.cog @@ -5,6 +5,8 @@ #include "commands.hpp" #include "internal/core.hpp" +#include "internal/bottles.hpp" +#include "internal/launch.hpp" #include "cellar.hpp" #include "help.hpp" @@ -21,39 +23,51 @@ vector cellar::commands::list_commands() { return result; } -map cellar::commands::core_commands() { - map result; /*[[[cog import cog + import os import os.path - with open("src/commands.txt") as commandfile: - for line in commandfile: - linesplit = line.strip().split(" ") - name = linesplit[0] - func = linesplit[1] + def recurs_command_plumbing(dirname): + print(" -- Recursing into", dirname) + for diritem in os.listdir(dirname): + itempath = os.path.join(dirname, diritem) + if os.path.isdir(itempath): + recurs_command_plumbing(itempath) + elif diritem == "commands.txt": + print(" -- Found commands file in", dirname + ", processing...") + base = os.path.basename(dirname) + cog.outl("map cellar::commands::{0}_commands() ".format(base) + "{") + cog.outl(" map result;") + with open(os.path.join(dirname, "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)) + cog.outl("result.insert(pair(\"{0}\", &{2}::{1}));".format(name, func, base)) - if (len(linesplit) > 2): - desc = " ".join(linesplit[2:]) # Rest of line assumed to be description - cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" - .format(name, desc - .replace("\\", "\\\\") - .replace("\"", "\\\""))) - # the replace methods escape " and \ characters - else: - print("-- No description is available for the {0} command.".format(name)) + if (len(linesplit) > 2): + desc = " ".join(linesplit[2:]) # Rest of line assumed to be description + cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" + .format(name, desc + .replace("\\", "\\\\") + .replace("\"", "\\\""))) + # the replace methods escape " and \ characters + else: + print("-- No description is available for the {0} command.".format(name)) - if os.path.exists("src/help/" + name): - cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) - with open("src/help/" + name) as detailsfile: - for detail in detailsfile: - cog.out(detail, trimblanklines=True) - cog.out(")\");") - else: - print("-- No details are available for the {0} command.".format(name)) + if os.path.exists("src/{0}/help/{1}".format(base, name)): + cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) + with open("src/{0}/help/{1}".format(base, name)) as detailsfile: + for detail in detailsfile: + cog.out(detail, trimblanklines=True) + cog.out(")\");") + else: + print("-- No details are available for the {0} command.".format(name)) + cog.outl(" return result;") + cog.outl("}") + + recurs_command_plumbing("src") ]]]*/ //[[[end]]] - return result; -} diff --git a/src/commands.txt b/src/core/commands.txt similarity index 100% rename from src/commands.txt rename to src/core/commands.txt diff --git a/src/help/help b/src/core/help/help similarity index 100% rename from src/help/help rename to src/core/help/help diff --git a/src/help/version b/src/core/help/version similarity index 100% rename from src/help/version rename to src/core/help/version diff --git a/src/help/help.cpp b/src/help/help.cpp index ab4e52c..7b4918c 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -13,7 +13,7 @@ using namespace std; using namespace cellar; -void cellar::commands::help_command(int argc, vector argv) { +void cellar::core::help_command(int argc, vector argv) { vector commands = list_commands(); cellar::print_header(); diff --git a/src/launch/commands.cpp.cog b/src/launch/commands.cpp.cog deleted file mode 100644 index ada2414..0000000 --- a/src/launch/commands.cpp.cog +++ /dev/null @@ -1,49 +0,0 @@ -// vim: filetype=cpp : -#include - -#include "launch.hpp" -#include "internal/launch.hpp" -#include "commands.hpp" -#include "dll.hpp" -#include "help.hpp" - -using namespace std; -using namespace cellar::launch; -using namespace cellar::commands; - -DLL_PUBLIC map cellar::commands::launch_commands() { - map result; -/*[[[cog - import cog - import os - - with open("src/launch/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)) - - if (len(linesplit) > 2): - desc = " ".join(linesplit[2:]) # Rest of line assumed to be description - cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" - .format(name, desc - .replace("\\", "\\\\") - .replace("\"", "\\\""))) - # the replace methods escape " and \ characters - else: - print("-- No description is available for the {0} command.".format(name)) - - if os.path.exists("src/launch/help/" + name): - cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) - with open("src/launch/help/" + name) as detailsfile: - for detail in detailsfile: - cog.out(detail, trimblanklines=True) - cog.out(")\");") - else: - print("-- No details are available for the {0} command.".format(name)) - ]]]*/ -//[[[end]]] - return result; -} diff --git a/src/version.cpp.cog b/src/version.cpp.cog index c478ca1..e7d0bef 100644 --- a/src/version.cpp.cog +++ b/src/version.cpp.cog @@ -43,6 +43,6 @@ string cellar::version::short_version() { //[[[end]]] } -void cellar::commands::print_version(int argc, vector argv) { +void cellar::core::print_version(int argc, vector argv) { cellar::output::statement(short_version()); }