Commit 7aaa94f5 authored by aggsol's avatar aggsol 🙉

name dot file output

parent 9499f43b
Pipeline #26624555 failed with stage
in 1 minute and 36 seconds
...@@ -17,9 +17,9 @@ Helper tool for gamebooks written in Asciidoc ...@@ -17,9 +17,9 @@ Helper tool for gamebooks written in Asciidoc
-i, --input <file> Input file in Asciidoctor format -i, --input <file> Input file in Asciidoctor format
-o, --output <file> Output file, default is stdout -o, --output <file> Output file, default is stdout
-s, --seed <number> Shuffle seed, default: 12345 -s, --seed <number> Shuffle seed, default: 12345
-d, --dot-file <file> Create a dot file named graph.dot
Flags: Flags:
-d, --dot-file Create a dot file named graph.dot
-h, --help Show this help text -h, --help Show this help text
-m, --mix-sections Shuffle the sections -m, --mix-sections Shuffle the sections
-n, --no-color Disable colored output -n, --no-color Disable colored output
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "Graph.hpp" #include "Graph.hpp"
#include <array> #include <array>
#include <cassert>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <fstream> #include <fstream>
...@@ -105,9 +106,19 @@ namespace ...@@ -105,9 +106,19 @@ namespace
namespace bodhi namespace bodhi
{ {
Graph::Graph(const std::string& filename)
: m_filename(filename)
{
if(filename.empty())
{
throw std::runtime_error("Missing dot filename");
}
}
void Graph::createDotFile(const std::map<int, Section>& sections) void Graph::createDotFile(const std::map<int, Section>& sections)
{ {
std::ofstream dotfile("graph.dot"); std::ofstream dotfile(m_filename);
if(not dotfile.is_open()) if(not dotfile.is_open())
{ {
throw std::runtime_error("Cannot write dot file"); throw std::runtime_error("Cannot write dot file");
......
...@@ -26,10 +26,11 @@ namespace bodhi ...@@ -26,10 +26,11 @@ namespace bodhi
class Graph class Graph
{ {
public: public:
explicit Graph(const std::string& filename);
void createDotFile(const std::map<int, Section>& sections); void createDotFile(const std::map<int, Section>& sections);
private: private:
std::string m_filename;
}; };
} }
......
...@@ -45,9 +45,9 @@ namespace ...@@ -45,9 +45,9 @@ namespace
<< " -i, --input <file> Input file in Asciidoctor format\n" << " -i, --input <file> Input file in Asciidoctor format\n"
<< " -o, --output <file> Output file, default is stdout\n" << " -o, --output <file> Output file, default is stdout\n"
<< " -s, --seed <number> Shuffle seed, default: 12345\n" << " -s, --seed <number> Shuffle seed, default: 12345\n"
<< " -d, --dot-file <file> Create a dot file named graph.dot\n"
<< "\n" << "\n"
<< "Flags:\n" << "Flags:\n"
<< " -d, --dot-file Create a dot file named graph.dot\n"
<< " -h, --help Show this help text\n" << " -h, --help Show this help text\n"
<< " -m, --mix-sections Shuffle the sections\n" << " -m, --mix-sections Shuffle the sections\n"
<< " -n, --no-color Disable colored output\n" << " -n, --no-color Disable colored output\n"
...@@ -74,11 +74,13 @@ int main(int argc, char* argv[]) ...@@ -74,11 +74,13 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
auto input = args.getOpt<std::string>("i", "input", "<missing input file>"); const std::string NONE = "<none>";
auto input = args.getOpt<std::string>("i", "input", NONE);
auto output = args.getOpt<std::string>("o", "output", "stdout"); auto output = args.getOpt<std::string>("o", "output", "stdout");
auto seed = args.getOpt<unsigned>("s", "seed", 12345); auto seed = args.getOpt<unsigned>("s", "seed", 12345);
auto mix = args.getOpt("m", "mix-sections"); auto mix = args.getOpt("m", "mix-sections");
auto dot = args.getOpt("d", "dot-file"); auto dot = args.getOpt<std::string>("d", "dot-file", NONE);
auto verbose = args.getOpt("v", "verbose"); auto verbose = args.getOpt("v", "verbose");
auto noColor = args.getOpt("n", "no-color"); auto noColor = args.getOpt("n", "no-color");
...@@ -87,7 +89,7 @@ int main(int argc, char* argv[]) ...@@ -87,7 +89,7 @@ int main(int argc, char* argv[])
rang::setControlMode(rang::control::Off); rang::setControlMode(rang::control::Off);
} }
if(mix && dot) if(mix && dot != NONE)
{ {
std::cerr << rang::fg::red std::cerr << rang::fg::red
<< "Error : Cannot combine --mix-sections and --dot-file\n" << "Error : Cannot combine --mix-sections and --dot-file\n"
...@@ -173,9 +175,9 @@ int main(int argc, char* argv[]) ...@@ -173,9 +175,9 @@ int main(int argc, char* argv[])
} }
} }
if(dot) if(dot != NONE)
{ {
bodhi::Graph graph; bodhi::Graph graph(dot);
graph.createDotFile(sections); graph.createDotFile(sections);
return 0; 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