Commit 18180697 authored by aggsol's avatar aggsol 🙉

added help text

parent eeb67160
......@@ -30,11 +30,45 @@
#include <set>
#include <string>
namespace
{
void printUsage()
{
std::cout << "Usage: gamebook-checker [OPTIONS]\n"
<< "Check gamebook sections in Asciidoctor format\n"
<< "Example: gamebook-checker -i sections.adoc\n"
<< "\n"
<< "Options:\n"
<< " -i, --input <file> Input file in Asciidoctor format\n"
<< " -o, --output <file> Output file, default is stdout\n"
<< " -s, --seed <number> Shuffle seed, default: 12345\n"
<< "\n"
<< "Flags:\n"
<< " -d, --dot-file Create a dot file named graph.dot\n"
<< " -h, --help Show this help text\n"
<< " -m, --mix-sections Shuffle the sections\n"
<< " -v, --verbose Show additional information\n"
<< " --version Show version\n"
<< std::endl;
}
}
int main(int argc, char* argv[])
{
bodhi::CliArguments args(argc, argv);
// auto version = args.getOpt("", "version");
// auto help = args.getOpt("h", "help");
if(args.getOpt("", "version"))
{
std::cout << "v0.1.0\n";
return 0;
}
if(args.getOpt("h", "help"))
{
printUsage();
return 0;
}
auto input = args.getOpt<std::string>("i", "input", "<missing input file>");
auto output = args.getOpt<std::string>("o", "output", "stdout");
......@@ -45,141 +79,149 @@ int main(int argc, char* argv[])
std::map<int, bodhi::Section> sections;
bodhi::Parser parser(input);
if(parser.parse(sections))
try
{
return 101;
}
bodhi::Parser parser(input);
for(auto& s: sections)
{
// Set parents
for(auto child: s.second.m_children)
if(parser.parse(sections))
{
auto it = sections.find(child);
if(it != sections.end())
{
it->second.m_parents.insert(child);
}
else
{
std::cerr << "Error : Missing section: " << child
<< " linked from section: " << s.first << "\n";
}
return 101;
}
// Append empty lines for section padding
// std::cout << "last line='" << s.second.m_lines.back() << "'\n";
if(s.second.m_lines.back() != "")
{
s.second.m_lines.push_back("");
}
}
// Check parents
int last = -1;
for(auto& s: sections)
{
if(s.first > 1)
for(auto& s: sections)
{
if(s.first - last != 1)
// Set parents
for(auto child: s.second.m_children)
{
std::cerr << "Warning: Missing section(s): ";
for(int i=last+1; i<s.first; ++i)
auto it = sections.find(child);
if(it != sections.end())
{
std::cerr << i<< " ";
it->second.m_parents.insert(child);
}
else
{
std::cerr << "Error : Missing section: " << child
<< " linked from section: " << s.first << "\n";
}
std::cerr << "\n";
}
if(s.second.m_parents.size() == 0)
// Append empty lines for section padding
// std::cout << "last line='" << s.second.m_lines.back() << "'\n";
if(s.second.m_lines.back() != "")
{
assert(s.first == s.second.m_number);
std::cerr << "Warning: No reference to section: " << s.first << "\n";
s.second.m_lines.push_back("");
}
}
last = s.first;
}
if(verbose)
{
std::cout << "Line count: " << parser.lineCount() << "\n"
<< "Number of sections: " << sections.size() << "\n";
// Check parents
int last = -1;
for(auto& s: sections)
{
std::cout << "Section: " << s.second.m_number << "\n"
<< "-> Number of classes : " << s.second.m_classes.size() << "\n"
<< "-> Number of lines : " << s.second.m_lines.size() << "\n"
<< "-> Number of children: " << s.second.m_children.size() << "\n"
<< "-> Number of parents : " << s.second.m_parents.size() << "\n";
}
}
if(dot)
{
std::ofstream dotfile("graph.dot");
if(not dotfile.is_open())
{
throw std::runtime_error("Cannot write dot file");
}
dotfile << "digraph G {\n"
<< " node [style=filled fillcolor=white];\n";
for(auto& s: sections)
if(s.first > 1)
{
for(auto& c: s.second.m_children)
if(s.first - last != 1)
{
dotfile << " " << s.second.m_number << " -> " << c << ";\n";
std::cerr << "Warning: Missing section(s): ";
for(int i=last+1; i<s.first; ++i)
{
std::cerr << i<< " ";
}
std::cerr << "\n";
}
if(s.second.m_children.size() == 0)
if(s.second.m_parents.size() == 0)
{
dotfile << " " << s.second.m_number << " [peripheries=2];\n";
assert(s.first == s.second.m_number);
std::cerr << "Warning: No reference to section: " << s.first << "\n";
}
}
last = s.first;
}
dotfile << "}\n";
}
if(verbose)
{
std::cout << "Line count: " << parser.lineCount() << "\n"
<< "Number of sections: " << sections.size() << "\n";
if(mix)
{
auto resultMapping = bodhi::createSectionMapping(sections, seed);
for(auto& s: sections)
{
std::cout << "Section: " << s.second.m_number << "\n"
<< "-> Number of classes : " << s.second.m_classes.size() << "\n"
<< "-> Number of lines : " << s.second.m_lines.size() << "\n"
<< "-> Number of children: " << s.second.m_children.size() << "\n"
<< "-> Number of parents : " << s.second.m_parents.size() << "\n";
}
}
if(output == "stdout")
if(dot)
{
for(auto& s: sections)
std::ofstream dotfile("graph.dot");
if(not dotfile.is_open())
{
assert(s.first == s.second.m_number);
int shuffled = resultMapping.at(s.first);
throw std::runtime_error("Cannot write dot file");
}
dotfile << "digraph G {\n"
<< " node [style=filled fillcolor=white];\n";
std::cout << "[[section-" << shuffled << "]]\n"
<< "== " << shuffled << "\n";
for(auto& s: sections)
{
for(auto& c: s.second.m_children)
{
dotfile << " " << s.second.m_number << " -> " << c << ";\n";
}
if(s.second.m_children.size() == 0)
{
dotfile << " " << s.second.m_number << " [peripheries=2];\n";
}
}
for(auto& c: s.second.m_children)
dotfile << "}\n";
}
if(mix)
{
auto resultMapping = bodhi::createSectionMapping(sections, seed);
if(output == "stdout")
{
for(auto& s: sections)
{
std::string before = "<<section-";
before += std::to_string(c);
before += ">>";
assert(s.first == s.second.m_number);
int shuffled = resultMapping.at(s.first);
std::string after = "<<section-";
after += std::to_string(resultMapping.at(c));
after += ">>";
std::cout << "[[section-" << shuffled << "]]\n"
<< "== " << shuffled << "\n";
for(auto& c: s.second.m_children)
{
std::string before = "<<section-";
before += std::to_string(c);
before += ">>";
std::cout << "Mapping " << before << " to " << after << "\n";
std::string after = "<<section-";
after += std::to_string(resultMapping.at(c));
after += ">>";
std::cout << "Mapping " << before << " to " << after << "\n";
for(auto& l: s.second.m_lines)
{
l = bodhi::replaceSubStr(l, before, after);
}
}
for(auto& l: s.second.m_lines)
{
l = bodhi::replaceSubStr(l, before, after);
std::cout << l << "\n";
}
}
for(auto& l: s.second.m_lines)
{
std::cout << l << "\n";
}
}
}
}
catch(const std::exception& ex)
{
std::cerr << ex.what() << "\n"
<< "Try -h/--help\n";
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment