From a0a74729fc42f9a161023899bfef0077daaed177 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Thu, 18 Mar 2021 21:12:18 +0100 Subject: [PATCH] Configuration is made and initialized in the main. --- main.cpp | 27 +++++++++++++++++++++++++-- src/configuration.cpp | 2 ++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index eb96b4a..ed9dcdf 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,34 @@ #include +#include #include #include +#include "include/configuration.hpp" -int main() { +namespace po = boost::program_options; + +int main(int argc, char *argv[]) { // Create logger auto logger = spdlog::stdout_color_st("single_log"); spdlog::set_default_logger(logger); - std::cout << "Hello, World!" << std::endl; + + po::options_description description{ "Allowed options" }; + description.add_options()("help", "produce help message")("config", po::value(), "path to the config file"); + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, description), vm); + po::notify(vm); + + if (vm.count("help")) { + std::cout << description << '\n'; + return EXIT_SUCCESS; + } + + const gemini::Configuration configuration = [&]() -> gemini::Configuration { + if (vm.count("config")) { + spdlog::debug("config file was set to {}", vm["config"].as()); + return gemini::Configuration{ vm["config"].as() }; + } + return gemini::Configuration{}; + }(); + return EXIT_SUCCESS; } diff --git a/src/configuration.cpp b/src/configuration.cpp index dbc552f..468d96e 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -1,9 +1,11 @@ #include "../include/configuration.hpp" #include "../include/information.hpp" #include "../include/cache_files.hpp" +#include std::pair> gemini::Configuration::create_infos() const { simdjson::dom::parser parser; + spdlog::debug("Creating infos and cache if enabled"); const auto config = parser.load(filename); const Information infos{ config["cache"]["enable_cache"].get_bool(),