Added '--print-to' cli option to print all possible 'to' constraints in sequence diagrams

This commit is contained in:
Bartek Kryza
2023-08-31 22:28:25 +02:00
parent 1bd60b71ec
commit 51e0275db3
5 changed files with 63 additions and 20 deletions

View File

@@ -129,8 +129,10 @@ cli_flow_t cli_handler::parse(int argc, const char **argv)
"instead of actual location of `.clang-uml` file.");
app.add_flag("--no-metadata", no_metadata,
"Skip metadata (e.g. clang-uml version) from diagrams");
app.add_flag("--print-start-from", print_start_from,
"Print all possible 'start_from' values for a given diagram");
app.add_flag("--print-from,--print-start-from", print_from,
"Print all possible 'from' values for a given diagram");
app.add_flag("--print-to", print_to,
"Print all possible 'to' values for a given diagram");
app.add_flag("--no-validate", no_validate,
"Do not perform configuration file schema validation");
app.add_flag("--validate-only", validate_only,
@@ -149,7 +151,7 @@ cli_flow_t cli_handler::parse(int argc, const char **argv)
exit(app.exit(e)); // NOLINT(concurrency-mt-unsafe)
}
if (quiet || dump_config || print_start_from)
if (quiet || dump_config || print_from || print_to)
verbose = 0;
else
verbose++;
@@ -202,11 +204,10 @@ cli_flow_t cli_handler::handle_pre_config_options()
return cli_flow_t::kError;
}
if (print_start_from) {
if (print_from || print_to) {
if (diagram_names.size() != 1) {
LOG_ERROR(
"ERROR: '--print-start-from' requires specifying one diagram "
"name using '-n' option");
LOG_ERROR("ERROR: '--print-from' and '--print-to' require "
"specifying one diagram name using '-n' option");
return cli_flow_t::kError;
}
@@ -346,7 +347,8 @@ runtime_config cli_handler::get_runtime_config() const
runtime_config cfg;
cfg.generators = generators;
cfg.verbose = verbose;
cfg.print_start_from = print_start_from;
cfg.print_from = print_from;
cfg.print_to = print_to;
cfg.progress = progress;
cfg.thread_count = thread_count;

View File

@@ -33,7 +33,8 @@ namespace clanguml::cli {
struct runtime_config {
int verbose{};
std::vector<clanguml::common::generator_type_t> generators{};
bool print_start_from{};
bool print_from{};
bool print_to{};
bool progress{};
unsigned int thread_count{};
};
@@ -173,7 +174,8 @@ public:
std::optional<std::string> add_include_diagram;
std::optional<std::string> add_diagram_from_template;
bool dump_config{false};
bool print_start_from{false};
bool print_from{false};
bool print_to{false};
std::optional<bool> paths_relative_to_pwd{};
std::vector<std::string> template_variables{};
bool list_templates{false};

View File

@@ -95,11 +95,20 @@ void generate_diagram_impl(const std::string &od, const std::string &name,
std::move(progress));
if constexpr (std::is_same_v<DiagramConfig, config::sequence_diagram>) {
if (rc.print_start_from) {
auto start_from_values = model->list_start_from_values();
if (rc.print_from) {
auto from_values = model->list_from_values();
for (const auto &start_from : start_from_values) {
std::cout << start_from << std::endl;
for (const auto &from : from_values) {
std::cout << from << std::endl;
}
return;
}
if (rc.print_to) {
auto to_values = model->list_to_values();
for (const auto &to : to_values) {
std::cout << "|" << to << "|" << std::endl;
}
return;

View File

@@ -193,18 +193,41 @@ bool diagram::should_include(
dynamic_cast<const common::model::source_location &>(p));
}
std::vector<std::string> diagram::list_start_from_values() const
std::vector<std::string> diagram::list_from_values() const
{
std::vector<std::string> result;
for (const auto &[from_id, act] : sequences_) {
const auto &from_activity = *(participants_.at(from_id));
result.push_back(from_activity.full_name(false));
const auto &full_name = from_activity.full_name(false);
if (!full_name.empty())
result.push_back(full_name);
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
return result;
}
std::vector<std::string> diagram::list_to_values() const
{
std::vector<std::string> result;
for (const auto &[from_id, act] : sequences_) {
for (const auto &m : act.messages()) {
if (participants_.count(m.to()) > 0) {
const auto &to_activity = *(participants_.at(m.to()));
const auto &full_name = to_activity.full_name(false);
if (!full_name.empty())
result.push_back(full_name);
}
}
}
std::sort(result.begin(), result.end());
result.erase(std::unique(result.begin(), result.end()), result.end());
return result;
}

View File

@@ -232,11 +232,18 @@ public:
bool should_include(const sequence_diagram::model::participant &p) const;
/**
* @brief Get list of all possible 'start_from' values in the model
* @brief Get list of all possible 'from' values in the model
*
* @return List of all possible 'start_from' values
* @return List of all possible 'from' values
*/
std::vector<std::string> list_start_from_values() const;
std::vector<std::string> list_from_values() const;
/**
* @brief Get list of all possible 'to' values in the model
*
* @return List of all possible 'to' values
*/
std::vector<std::string> list_to_values() const;
/**
* @brief Generate a list of message chains matching a from_to constraint