Configuration is made and initialized in the main.

This commit is contained in:
Pcornat 2021-03-18 21:12:18 +01:00
parent b71a49cfbe
commit a0a74729fc
No known key found for this signature in database
GPG Key ID: 873C3ACCF970C74E
2 changed files with 27 additions and 2 deletions

View File

@ -1,11 +1,34 @@
#include <iostream>
#include <boost/program_options.hpp>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#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<std::string>(), "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<std::string>());
return gemini::Configuration{ vm["config"].as<std::string>() };
}
return gemini::Configuration{};
}();
return EXIT_SUCCESS;
}

View File

@ -1,9 +1,11 @@
#include "../include/configuration.hpp"
#include "../include/information.hpp"
#include "../include/cache_files.hpp"
#include <spdlog/spdlog.h>
std::pair<gemini::Information, std::optional<gemini::CacheFiles>> 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(),