Moved environment defaulting to class scope

This commit is contained in:
Nav
2021-05-24 21:05:17 +01:00
parent ce480a996c
commit 76e5fba383
2 changed files with 12 additions and 6 deletions

View File

@@ -83,17 +83,16 @@ void Application::startup() {
this->blockAllSignalsOnCurrentThread();
this->signalHandlerThread = std::thread(&SignalHandler::run, std::ref(this->signalHandler));
auto environmentName = this->selectedEnvironmentName.value_or("default");
Logger::info("Selected environment: " + environmentName);
Logger::info("Selected environment: " + this->selectedEnvironmentName);
Logger::debug("Number of environments extracted from config: "
+ std::to_string(this->applicationConfig.environments.size()));
// Validate the selected environment
if (!applicationConfig.environments.contains(environmentName)) {
throw InvalidConfig("Environment (\"" + environmentName + "\") not found in configuration.");
if (!applicationConfig.environments.contains(this->selectedEnvironmentName)) {
throw InvalidConfig("Environment (\"" + this->selectedEnvironmentName + "\") not found in configuration.");
}
this->environmentConfig = applicationConfig.environments.at(environmentName);
this->environmentConfig = applicationConfig.environments.at(this->selectedEnvironmentName);
this->insightConfig = this->environmentConfig.insightConfig.value_or(this->applicationConfig.insightConfig);
if (this->environmentConfig.debugServerConfig.has_value()) {

View File

@@ -89,7 +89,14 @@ namespace Bloom
EnvironmentConfig environmentConfig;
DebugServerConfig debugServerConfig;
InsightConfig insightConfig;
std::optional<std::string> selectedEnvironmentName;
/**
* The project environment selected by the user.
*
* If an environment name is not provided as an argument when running Bloom, Bloom will fallback to the
* environment named "default".
*/
std::string selectedEnvironmentName = "default";
/**
* Some CLI arguments are interpreted as commands and thus require specific handler methods to be called.