From 76e5fba38321256de263ca0ebb2256c824201d5a Mon Sep 17 00:00:00 2001 From: Nav Date: Mon, 24 May 2021 21:05:17 +0100 Subject: [PATCH] Moved environment defaulting to class scope --- src/Application.cpp | 9 ++++----- src/Application.hpp | 9 ++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index d03e7b7b..2f0e1fcb 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -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()) { diff --git a/src/Application.hpp b/src/Application.hpp index 72ee67eb..2231cd63 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -89,7 +89,14 @@ namespace Bloom EnvironmentConfig environmentConfig; DebugServerConfig debugServerConfig; InsightConfig insightConfig; - std::optional 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.