diff --git a/src/basics/config/ConfigurationFile.h b/src/basics/config/ConfigurationFile.h index 3bf9e807280132afa81fa0473781896e87fbfd66..c0cd06ca8310641b4adc86139a357f2a5993ce78 100644 --- a/src/basics/config/ConfigurationFile.h +++ b/src/basics/config/ConfigurationFile.h @@ -1,6 +1,8 @@ #ifndef BASICS_CONFIGURATIONFILE_H #define BASICS_CONFIGURATIONFILE_H +#include "Logger.h" +#include <filesystem> #include <map> #include <vector> #include <sstream> @@ -68,6 +70,26 @@ public: template<class T> T getValue(const std::string& key, T defaultValue) const; + static ConfigurationFile loadConfig(int argc, char *argv[], std::filesystem::path configPath, std::string defaultConfigName = "config.txt") + { + // the config file's default name can be replaced by passing a command line argument + + std::string configName = defaultConfigName; + + if (argc > 1) + { + configName = argv[1]; + VF_LOG_INFO("Using configFile command line argument: {}", configName); + } else { + VF_LOG_INFO("Using default config name: {}", configName); + } + + configPath.replace_filename(configName); + vf::basics::ConfigurationFile config; + config.load(configPath.string()); + return config; + } + private: //! the container std::map<std::string, std::string> data;