Added list-diagrams cli options
This commit is contained in:
@@ -27,6 +27,20 @@ config load(const std::string &config_file)
|
||||
return doc.as<config>();
|
||||
}
|
||||
|
||||
std::string to_string(const diagram_type t)
|
||||
{
|
||||
switch (t) {
|
||||
case diagram_type::class_diagram:
|
||||
return "class";
|
||||
case diagram_type::sequence_diagram:
|
||||
return "sequence";
|
||||
case diagram_type::package_diagram:
|
||||
return "package";
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool diagram::should_include_entities(const std::string &ent)
|
||||
{
|
||||
for (const auto &ex : exclude.entity_types) {
|
||||
@@ -107,6 +121,8 @@ bool diagram::should_include(const clanguml::common::model::scope_t scope) const
|
||||
return false;
|
||||
}
|
||||
|
||||
diagram_type class_diagram::type() const { return diagram_type::class_diagram; }
|
||||
|
||||
bool class_diagram::has_class(std::string clazz)
|
||||
{
|
||||
for (const auto &c : classes) {
|
||||
@@ -123,6 +139,16 @@ bool class_diagram::has_class(std::string clazz)
|
||||
return false;
|
||||
}
|
||||
|
||||
diagram_type sequence_diagram::type() const
|
||||
{
|
||||
return diagram_type::sequence_diagram;
|
||||
}
|
||||
|
||||
diagram_type package_diagram::type() const
|
||||
{
|
||||
return diagram_type::package_diagram;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,15 @@ struct filter {
|
||||
std::vector<common::model::scope_t> scopes;
|
||||
};
|
||||
|
||||
enum class diagram_type { class_diagram, sequence_diagram, package_diagram };
|
||||
|
||||
std::string to_string(const diagram_type t);
|
||||
|
||||
struct diagram {
|
||||
virtual ~diagram() = default;
|
||||
|
||||
virtual diagram_type type() const = 0;
|
||||
|
||||
std::string name;
|
||||
std::vector<std::string> glob;
|
||||
std::vector<std::string> using_namespace;
|
||||
@@ -89,6 +95,8 @@ struct source_location {
|
||||
struct class_diagram : public diagram {
|
||||
virtual ~class_diagram() = default;
|
||||
|
||||
diagram_type type() const override;
|
||||
|
||||
std::vector<std::string> classes;
|
||||
bool include_relations_also_as_members{true};
|
||||
|
||||
@@ -98,11 +106,15 @@ struct class_diagram : public diagram {
|
||||
struct sequence_diagram : public diagram {
|
||||
virtual ~sequence_diagram() = default;
|
||||
|
||||
diagram_type type() const override;
|
||||
|
||||
std::vector<source_location> start_from;
|
||||
};
|
||||
|
||||
struct package_diagram : public diagram {
|
||||
virtual ~package_diagram() = default;
|
||||
|
||||
diagram_type type() const override;
|
||||
};
|
||||
|
||||
struct config {
|
||||
|
||||
29
src/main.cc
29
src/main.cc
@@ -24,6 +24,7 @@
|
||||
#include "package_diagram/generators/plantuml/package_diagram_generator.h"
|
||||
#include "sequence_diagram/generators/plantuml/sequence_diagram_generator.h"
|
||||
|
||||
#include "config/config.h"
|
||||
#include "util/util.h"
|
||||
|
||||
#include <cli11/CLI11.hpp>
|
||||
@@ -39,6 +40,8 @@ using namespace clanguml;
|
||||
using config::config;
|
||||
using cx::compilation_database;
|
||||
|
||||
void print_diagrams_list(const clanguml::config::config &cfg);
|
||||
|
||||
int main(int argc, const char *argv[])
|
||||
{
|
||||
CLI::App app{"Clang-based PlantUML diagram generator for C++"};
|
||||
@@ -48,6 +51,7 @@ int main(int argc, const char *argv[])
|
||||
std::vector<std::string> diagram_names{};
|
||||
std::optional<std::string> output_directory;
|
||||
bool verbose{false};
|
||||
bool list_diagrams{false};
|
||||
|
||||
app.add_option(
|
||||
"-c,--config", config_path, "Location of configuration file");
|
||||
@@ -58,6 +62,8 @@ int main(int argc, const char *argv[])
|
||||
app.add_option("-o,--output-directory", output_directory,
|
||||
"Override output directory specified in config file");
|
||||
app.add_flag("-v,--verbose", verbose, "Verbose logging");
|
||||
app.add_flag("-l,--list-diagrams", list_diagrams,
|
||||
"Print list of diagrams defined in the config file");
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
@@ -70,6 +76,11 @@ int main(int argc, const char *argv[])
|
||||
|
||||
auto config = clanguml::config::load(config_path);
|
||||
|
||||
if (list_diagrams) {
|
||||
print_diagrams_list(config);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOG_INFO("Loading compilation database from {} directory",
|
||||
config.compilation_database_dir);
|
||||
|
||||
@@ -86,6 +97,7 @@ int main(int argc, const char *argv[])
|
||||
continue;
|
||||
|
||||
using clanguml::config::class_diagram;
|
||||
using clanguml::config::diagram_type;
|
||||
using clanguml::config::package_diagram;
|
||||
using clanguml::config::sequence_diagram;
|
||||
|
||||
@@ -93,7 +105,7 @@ int main(int argc, const char *argv[])
|
||||
std::ofstream ofs;
|
||||
ofs.open(path, std::ofstream::out | std::ofstream::trunc);
|
||||
|
||||
if (std::dynamic_pointer_cast<class_diagram>(diagram)) {
|
||||
if (diagram->type() == diagram_type::class_diagram) {
|
||||
auto model =
|
||||
clanguml::class_diagram::generators::plantuml::generate(
|
||||
db, name, dynamic_cast<class_diagram &>(*diagram));
|
||||
@@ -102,7 +114,7 @@ int main(int argc, const char *argv[])
|
||||
dynamic_cast<clanguml::config::class_diagram &>(*diagram),
|
||||
model);
|
||||
}
|
||||
else if (std::dynamic_pointer_cast<sequence_diagram>(diagram)) {
|
||||
else if (diagram->type() == diagram_type::sequence_diagram) {
|
||||
auto model =
|
||||
clanguml::sequence_diagram::generators::plantuml::generate(
|
||||
db, name, dynamic_cast<sequence_diagram &>(*diagram));
|
||||
@@ -111,7 +123,7 @@ int main(int argc, const char *argv[])
|
||||
dynamic_cast<clanguml::config::sequence_diagram &>(*diagram),
|
||||
model);
|
||||
}
|
||||
else if (std::dynamic_pointer_cast<package_diagram>(diagram)) {
|
||||
else if (diagram->type() == diagram_type::package_diagram) {
|
||||
auto model =
|
||||
clanguml::package_diagram::generators::plantuml::generate(
|
||||
db, name, dynamic_cast<package_diagram &>(*diagram));
|
||||
@@ -128,3 +140,14 @@ int main(int argc, const char *argv[])
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void print_diagrams_list(const clanguml::config::config &cfg)
|
||||
{
|
||||
using std::cout;
|
||||
|
||||
cout << "The following diagrams are defined in the config file:\n";
|
||||
for (const auto &[name, diagram] : cfg.diagrams) {
|
||||
cout << " - " << name << " [" << to_string(diagram->type()) << "]";
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user