in include/poac/subcmd/graph.hpp [107:154]
int _main(VS&& argv) {
namespace fs = boost::filesystem;
namespace exception = core::exception;
if (const auto output_op = util::argparse::use_get(argv, "-o", "--output")) {
fs::path output = *output_op;
if (output.extension() == ".png") {
if (util::_command::has_command("dot")) {
const auto [g, names] = create_graph();
const std::string file_dot = output.stem().string() + ".dot";
std::ofstream file(file_dot);
boost::write_graphviz(file, g, boost::make_label_writer(&names[0]));
util::command("dot -Tpng " + file_dot + " -o " + output.string()).exec();
fs::remove(file_dot);
io::cli::echo(io::cli::status_done());
}
else {
throw exception::error(
"To output with .png you need graphviz.\n"
"You need to install the graphviz.\n"
"Or please consider outputting in .dot format.");
}
}
else if (output.extension() == ".dot") {
const auto [g, names] = create_graph();
std::ofstream file(output.string());
boost::write_graphviz(file, g, boost::make_label_writer(&names[0]));
io::cli::echo(io::cli::status_done());
}
else {
throw exception::error(
"The extension of the output file must be .dot or .png.");
}
}
else {
const auto [g, names] = create_graph();
(void)names; // error: unused variable
boost::graph_traits<Graph>::edge_iterator itr, end;
for(tie(itr, end) = edges(g); itr != end; ++itr) {
std::cout << boost::get(&Vertex::name, g)[source(*itr, g)] << " -> "
<< boost::get(&Vertex::name, g)[target(*itr, g)] << '\n';
}
}
return EXIT_SUCCESS;
}