fixed issue #14

This commit is contained in:
Nicholas O'Connor 2017-04-09 22:08:10 -07:00
parent e4a8abf27a
commit db813a7d7b
3 changed files with 89 additions and 90 deletions

View File

@ -4,46 +4,45 @@
#include "bottles.hpp" #include "bottles.hpp"
#include "internal/bottles.hpp" #include "internal/bottles.hpp"
#include "commands.hpp" #include "commands.hpp"
#include "dll.hpp"
#include "help.hpp" #include "help.hpp"
using namespace std; using namespace std;
using namespace cellar::bottles; using namespace cellar::bottles;
using namespace cellar::commands; using namespace cellar::commands;
DLL_PUBLIC map<string, CommandFunction> cellar::commands::bottles_commands() { map<string, CommandFunction> cellar::commands::bottles_commands() {
map<string, CommandFunction> result; map<string, CommandFunction> result;
/*[[[cog /*[[[cog
import cog import cog
import os import os
with open("src/bottles/commands.txt") as commandfile: with open("src/bottles/commands.txt") as commandfile:
for line in commandfile: for line in commandfile:
linesplit = line.strip().split(" ") linesplit = line.strip().split(" ")
name = linesplit[0] name = linesplit[0]
func = linesplit[1] func = linesplit[1]
cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func)) cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func))
if (len(linesplit) > 2): if (len(linesplit) > 2):
desc = " ".join(linesplit[2:]) # Rest of line assumed to be description desc = " ".join(linesplit[2:]) # Rest of line assumed to be description
cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");"
.format(name, desc .format(name, desc
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replace("\"", "\\\""))) .replace("\"", "\\\"")))
# the replace methods escape " and \ characters # the replace methods escape " and \ characters
else: else:
print("-- No description is available for the {0} command.".format(name)) print("-- No description is available for the {0} command.".format(name))
if os.path.exists("src/bottles/help/" + name): if os.path.exists("src/bottles/help/" + name):
cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name))
with open("src/bottles/help/" + name) as detailsfile: with open("src/bottles/help/" + name) as detailsfile:
for detail in detailsfile: for detail in detailsfile:
cog.out(detail, dedent=True, trimblanklines=True) cog.out(detail, trimblanklines=True)
cog.out(")\");") cog.out(")\");")
else: else:
print("-- No details are available for the {0} command.".format(name)) print("-- No details are available for the {0} command.".format(name))
]]]*/ ]]]*/
//[[[end]]] //[[[end]]]
return result; return result;
} }

View File

@ -23,37 +23,37 @@ vector<string> cellar::commands::list_commands() {
map<string, CommandFunction> cellar::commands::core_commands() { map<string, CommandFunction> cellar::commands::core_commands() {
map<string, CommandFunction> result; map<string, CommandFunction> result;
/*[[[cog /*[[[cog
import cog import cog
import os.path import os.path
with open("src/commands.txt") as commandfile: with open("src/commands.txt") as commandfile:
for line in commandfile: for line in commandfile:
linesplit = line.strip().split(" ") linesplit = line.strip().split(" ")
name = linesplit[0] name = linesplit[0]
func = linesplit[1] func = linesplit[1]
cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func)) cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func))
if (len(linesplit) > 2): if (len(linesplit) > 2):
desc = " ".join(linesplit[2:]) # Rest of line assumed to be description desc = " ".join(linesplit[2:]) # Rest of line assumed to be description
cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");"
.format(name, desc .format(name, desc
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replace("\"", "\\\""))) .replace("\"", "\\\"")))
# the replace methods escape " and \ characters # the replace methods escape " and \ characters
else: else:
print("-- No description is available for the {0} command.".format(name)) print("-- No description is available for the {0} command.".format(name))
if os.path.exists("src/help/" + name): if os.path.exists("src/help/" + name):
cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name))
with open("src/help/" + name) as detailsfile: with open("src/help/" + name) as detailsfile:
for detail in detailsfile: for detail in detailsfile:
cog.out(detail, dedent=True, trimblanklines=True) cog.out(detail, trimblanklines=True)
cog.out(")\");") cog.out(")\");")
else: else:
print("-- No details are available for the {0} command.".format(name)) print("-- No details are available for the {0} command.".format(name))
]]]*/ ]]]*/
//[[[end]]] //[[[end]]]
return result; return result;
} }

View File

@ -13,37 +13,37 @@ using namespace cellar::commands;
DLL_PUBLIC map<string, CommandFunction> cellar::commands::launch_commands() { DLL_PUBLIC map<string, CommandFunction> cellar::commands::launch_commands() {
map<string, CommandFunction> result; map<string, CommandFunction> result;
/*[[[cog /*[[[cog
import cog import cog
import os import os
with open("src/launch/commands.txt") as commandfile: with open("src/launch/commands.txt") as commandfile:
for line in commandfile: for line in commandfile:
linesplit = line.strip().split(" ") linesplit = line.strip().split(" ")
name = linesplit[0] name = linesplit[0]
func = linesplit[1] func = linesplit[1]
cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func)) cog.outl("result.insert(pair<string,CommandFunction>(\"{0}\", &{1}));".format(name, func))
if (len(linesplit) > 2): if (len(linesplit) > 2):
desc = " ".join(linesplit[2:]) # Rest of line assumed to be description desc = " ".join(linesplit[2:]) # Rest of line assumed to be description
cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");" cog.outl("cellar::help::set_description(\"{0}\", \"{1}\");"
.format(name, desc .format(name, desc
.replace("\\", "\\\\") .replace("\\", "\\\\")
.replace("\"", "\\\""))) .replace("\"", "\\\"")))
# the replace methods escape " and \ characters # the replace methods escape " and \ characters
else: else:
print("-- No description is available for the {0} command.".format(name)) print("-- No description is available for the {0} command.".format(name))
if os.path.exists("src/launch/help/" + name): if os.path.exists("src/launch/help/" + name):
cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name)) cog.out("cellar::help::set_details(\"{0}\", R\"(".format(name))
with open("src/launch/help/" + name) as detailsfile: with open("src/launch/help/" + name) as detailsfile:
for detail in detailsfile: for detail in detailsfile:
cog.out(detail, dedent=True, trimblanklines=True) cog.out(detail, trimblanklines=True)
cog.out(")\");") cog.out(")\");")
else: else:
print("-- No details are available for the {0} command.".format(name)) print("-- No details are available for the {0} command.".format(name))
]]]*/ ]]]*/
//[[[end]]] //[[[end]]]
return result; return result;
} }