Save one of the last spots in our Shell + Git + GitLab introdoctury course on Friday and Monday next week. 👉 Register here.

Commit 14c7e1e9 authored by Pape, David (FWCC) - 139658's avatar Pape, David (FWCC) - 139658
Browse files

Moving configuration into own file.

parent 9db32fab
......@@ -6,7 +6,7 @@
#include "CIEnvironment.h"
#include "CIJobFactory.h"
#include "libconfig.h++"
#include "config.h"
#include "logging.h"
#include "spdlog/spdlog.h"
......@@ -35,25 +35,11 @@ int main(int argc, char *argv[]) {
std::cerr << "Could not get home directory" << std::endl;
return 50;
}
std::filesystem::path home(h);
std::filesystem::path cfgFile = home / ".config"
/ (program_invocation_short_name + std::string(".cfg"));
auto config = config::make(home);
libconfig::Config config;
try {
config.readFile(cfgFile.c_str());
} catch(const libconfig::FileIOException &fioex) {
std::cerr << "I/O error while reading config file " << cfgFile
<< ": " << fioex.what() << std::endl;
return 40;
} catch(const libconfig::ParseException &pex) {
std::cerr << "Error parsing config file at " << pex.getFile() << ":" << pex.getLine()
<< ": " << pex.getError() << std::endl;
return 39;
}
int result = logging::setup(config, home);
int result = logging::setup(*config, home);
if (result != 0)
return result;
SPDLOG_INFO("Started {}", program_invocation_name);
......@@ -74,13 +60,13 @@ int main(int argc, char *argv[]) {
return env.GetExitSystemFailure();
}
std::string jobStage = argv[1];
std::string jobStage = argv[1];
std::string scriptName = argv[2] ? argv[2] : "";
std::string subStage = argv[3] ? argv[3] : "";
std::string subStage = argv[3] ? argv[3] : "";
bool unifiedOutput;
try {
unifiedOutput = static_cast<bool>(config.lookup("unified_output"));
unifiedOutput = static_cast<bool>(config->lookup("unified_output"));
} catch (const libconfig::SettingNotFoundException &) {
unifiedOutput = true;
}
......@@ -93,6 +79,6 @@ int main(int argc, char *argv[]) {
result = job->Run();
delete config;
return result;
}
#include "config.h"
#include <iostream>
libconfig::Config *config::make(const std::filesystem::path &home) {
auto config = new libconfig::Config();
std::filesystem::path cfgFile = home / ".config"
/ (program_invocation_short_name + std::string(".cfg"));
try {
config->readFile(cfgFile.c_str());
} catch(const libconfig::FileIOException &) {
std::cerr << "Could not read config file " << cfgFile << std::endl;
} catch(const libconfig::ParseException &pex) {
std::cerr << "Error parsing config file at " << pex.getFile() << ":" << pex.getLine()
<< ": " << pex.getError() << std::endl;
}
return config;
}
#ifndef CONFIG_H
#define CONFIG_H
#include <filesystem>
#include "libconfig.h++"
namespace config {
libconfig::Config *make(const std::filesystem::path &home);
}
#endif // CONFIG_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment