From a5a8fb284cd63a78b8f6046f06c2a144b119e204 Mon Sep 17 00:00:00 2001 From: Nicholas O'Connor Date: Fri, 24 Mar 2017 23:05:31 -0700 Subject: [PATCH] help descriptions now understood by the cog files, no implementation yet, don't try to build this --- include/help.hpp | 15 +++++++++++++++ src/bottles/commands.cpp.cog | 8 ++++++++ src/commands.cpp.cog | 9 +++++++++ src/commands.txt | 2 +- src/help/help.cpp | 1 + src/launch/commands.cpp.cog | 8 ++++++++ 6 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 include/help.hpp diff --git a/include/help.hpp b/include/help.hpp new file mode 100644 index 0000000..7ba6a3e --- /dev/null +++ b/include/help.hpp @@ -0,0 +1,15 @@ +#ifndef __HELP_HPP +#define __HELP_HPP +#pragma once + +#include + +using namespace std; + +namespace cellar { + namespace help { + extern void set_description(string,string); + } +} + +#endif // __HELP_HPP diff --git a/src/bottles/commands.cpp.cog b/src/bottles/commands.cpp.cog index c2d2671..5630eab 100644 --- a/src/bottles/commands.cpp.cog +++ b/src/bottles/commands.cpp.cog @@ -22,6 +22,14 @@ DLL_PUBLIC map cellar::commands::bottles_commands() { 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 ]]]*/ //[[[end]]] return result; diff --git a/src/commands.cpp.cog b/src/commands.cpp.cog index 7b3ac3d..5899ea0 100644 --- a/src/commands.cpp.cog +++ b/src/commands.cpp.cog @@ -6,6 +6,7 @@ #include "commands.hpp" #include "internal/core.hpp" #include "cellar.hpp" +#include "help.hpp" using namespace std; using namespace cellar::commands; @@ -32,6 +33,14 @@ map cellar::commands::core_commands() { 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 ]]]*/ //[[[end]]] return result; diff --git a/src/commands.txt b/src/commands.txt index da23819..f5ba7ad 100644 --- a/src/commands.txt +++ b/src/commands.txt @@ -1,2 +1,2 @@ -version print_version +version print_version Prints version information. help help_command diff --git a/src/help/help.cpp b/src/help/help.cpp index 4cec2a8..6a2d1c1 100644 --- a/src/help/help.cpp +++ b/src/help/help.cpp @@ -3,6 +3,7 @@ #include "cellar.hpp" #include "internal/core.hpp" +#include "help.cpp" using namespace std; diff --git a/src/launch/commands.cpp.cog b/src/launch/commands.cpp.cog index 24f0fc2..402213c 100644 --- a/src/launch/commands.cpp.cog +++ b/src/launch/commands.cpp.cog @@ -22,6 +22,14 @@ DLL_PUBLIC map cellar::commands::launch_commands() { 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 ]]]*/ //[[[end]]] return result;