Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add way to use environment value for 'output' option #3817

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,37 @@ void Config::mergeConfig(Json::Value &a_config_, Json::Value &b_config_) {
}
bool isValidOutput(const Json::Value &config, const std::string &name,
const std::string &identifier) {
const auto isOutputMatches = [&](const std::string &output) -> bool {
if (output.substr(0, 1) == "$") {
auto *const environment_value = std::getenv(output.substr(1).c_str());
if (environment_value != nullptr) {
const std::string output_from_env = environment_value;
return output_from_env == name || output_from_env == identifier;
}

spdlog::warn("The environment value is unknown: {}", output);
}

return output == name || output == identifier;
};

if (config["output"].isArray()) {
for (auto const &output_conf : config["output"]) {
if (output_conf.isString()) {
auto config_output = output_conf.asString();

if (config_output.substr(0, 1) == "!") {
if (config_output.substr(1) == name || config_output.substr(1) == identifier) {
if (isOutputMatches(config_output.substr(1))) {
return false;
}

continue;
}
if (config_output == name || config_output == identifier) {

if (isOutputMatches(config_output)) {
return true;
}

if (config_output.substr(0, 1) == "*") {
return true;
}
Expand All @@ -147,11 +164,13 @@ bool isValidOutput(const Json::Value &config, const std::string &name,

if (config["output"].isString()) {
auto config_output = config["output"].asString();

if (!config_output.empty()) {
if (config_output.substr(0, 1) == "!") {
return config_output.substr(1) != name && config_output.substr(1) != identifier;
return !isOutputMatches(config_output.substr(1));
}
return config_output == name || config_output == identifier;

return isOutputMatches(config_output);
}
}

Expand Down