Added CLANGUML_GIT_TOPLEVEL_DIR env var for adjusting diagram link paths

This commit is contained in:
Bartek Kryza
2022-06-10 14:57:39 +02:00
parent 1d68608625
commit 2b8696130d
2 changed files with 17 additions and 0 deletions

View File

@@ -56,6 +56,16 @@ std::string get_process_output(const std::string &command)
return result;
}
std::string get_env(const std::string &name)
{
const char *value = std::getenv(name.c_str());
if (value == nullptr)
return {};
return std::string{value};
}
bool is_git_repository()
{
#if defined(_WIN32) || defined(_WIN64)
@@ -84,6 +94,11 @@ std::string get_git_commit()
std::string get_git_toplevel_dir()
{
const auto env_toplevel_dir = get_env("CLANGUML_GIT_TOPLEVEL_DIR");
if (!env_toplevel_dir.empty())
return env_toplevel_dir;
return trim(get_process_output("git rev-parse --show-toplevel"));
}

View File

@@ -62,6 +62,8 @@ void setup_logging(bool verbose);
std::string get_process_output(const std::string &command);
std::string get_env(const std::string &name);
bool is_git_repository();
std::string get_git_branch();