3 #include <boost/program_options.hpp>
7 #include "spdlog/sinks/rotating_file_sink.h"
10 std::filesystem::path input_file_path;
11 std::string log_level;
12 std::string log_output;
17 boost::program_options::options_description options_desc(
"Allowed options");
18 options_desc.add_options()(
"help,h",
"produce help message");
19 options_desc.add_options()(
20 "input_file_path,f", boost::program_options::value<std::filesystem::path>(&input_file_path),
21 "The path to the input file. Must be specified, otherwise the program will terminate. Can be inserted as positional argument.");
22 options_desc.add_options()(
"log_level,l", boost::program_options::value<std::string>(&log_level)->default_value(
"info"),
23 "The log level. Possible values: trace, debug, info, warning, error, critical, off");
24 options_desc.add_options()(
25 "log_output", boost::program_options::value<std::string>(&log_output)->default_value(
"std"),
26 "You can only choose between the output options std(only cl output) and file (only file output). Default: no file output");
27 options_desc.add_options()(
28 "fresh", boost::program_options::bool_switch(&fresh)->default_value(
false),
29 "Rerun the simulation from scratch without using any cached data. This will delete the whole output directory.");
31 boost::program_options::positional_options_description positional_options_desc;
32 positional_options_desc.add(
"input_file_path", -1);
34 boost::program_options::variables_map variables_map;
35 boost::program_options::store(
36 boost::program_options::command_line_parser(argc, argsv).options(options_desc).positional(positional_options_desc).run(),
38 boost::program_options::notify(variables_map);
40 if (log_output ==
"std" || log_output ==
"STD") {
42 }
else if (log_output ==
"file" || log_output ==
"FILE") {
46 std::cout <<
"Error: Invalid log output given. Options: no file output: 'std' and file output: 'file'" << std::endl;
52 if (argc <= 1 || variables_map.count(
"help")) {
53 std::stringstream help_message;
54 help_message << options_desc << std::endl;
58 if (!variables_map.count(
"input_file_path")) {
60 std::stringstream help_message;
61 help_message << options_desc << std::endl;
71 Logger::logger->warn(
"No simulation parameters provided. Try using a XML file as input.");
72 throw std::runtime_error(
"No simulation parameters provided. Try using a XML file as input.");
CLIParams parse_arguments(int argc, char *argsv[])
Parses the command line arguments.
SimulationParams merge_parameters(const CLIParams ¶ms_cli, const std::optional< SimulationParams > &file_params)
Merges the simulation parameters retrieved via the command line with the ones from the XML file....
static void update_level(std::string &log_level)
Sets the log level of the logger.
static std::shared_ptr< spdlog::logger > init_logger(LogType log_type=LogType::STD)
Initializes the logger.
static std::shared_ptr< spdlog::logger > logger
Publically accessible shared pointer to the logger.
Contains all parameters needed to run a simulation.
bool fresh
Flag to indicate whether the simulation should be run from scratch, or whether cached data should be ...