Skip to content

Commit

Permalink
Don't repeat yourself
Browse files Browse the repository at this point in the history
  • Loading branch information
dg0yt committed Apr 5, 2024
1 parent 56e7d63 commit 6ea9f2f
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions src/vcpkg/commands.depend-info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ namespace

namespace vcpkg
{
namespace
{
const char* get_dot_element_style(const std::string& label)
{
if (!Strings::contains(label, ':'))
return "";

if (Strings::ends_with(label, ":host"))
return " [color=gray51 fontcolor=gray51]";

return " [color=blue fontcolor=blue]";
}
}

std::string create_dot_as_string(const std::vector<PackageDependInfo>& depend_info)
{
int empty_node_count = 0;
Expand All @@ -173,17 +187,7 @@ namespace vcpkg

for (const auto& package : depend_info)
{
const char* node_style = "";
if (Strings::ends_with(package.package, ":host"))
{
node_style = " [color=gray51 fontcolor=gray51]";
}
else if (Strings::contains(package.package, ':'))
{
node_style = " [color=blue fontcolor=blue]";
}

fmt::format_to(std::back_inserter(s), "\"{}\"{};\n", package.package, node_style);
fmt::format_to(std::back_inserter(s), "\"{}\"{};\n", package.package, get_dot_element_style(package.package));
if (package.dependencies.empty())
{
empty_node_count++;
Expand All @@ -192,16 +196,7 @@ namespace vcpkg

for (const auto& d : package.dependencies)
{
const char* edge_style = " [color=blue fontcolor=blue]";
if (!Strings::contains(d, ':'))
{
edge_style = "";
}
else if (Strings::ends_with(d, ":host"))
{
edge_style = " [color=gray51 fontcolor=gray51]";
}
fmt::format_to(std::back_inserter(s), "\"{}\" -> \"{}\"{};\n", package.package, d, edge_style);
fmt::format_to(std::back_inserter(s), "\"{}\" -> \"{}\"{};\n", package.package, d, get_dot_element_style(d));
}
}

Expand Down

0 comments on commit 6ea9f2f

Please sign in to comment.