cleanup toml stuff a bit
This commit is contained in:
parent
0a0ab0703a
commit
dcda1bfd1c
11
src/main.cpp
11
src/main.cpp
|
@ -81,6 +81,7 @@ struct NanoSm {
|
||||||
int Run() {
|
int Run() {
|
||||||
ev.Post([this]() {
|
ev.Post([this]() {
|
||||||
this->SpawnAllApps();
|
this->SpawnAllApps();
|
||||||
|
nanosm::log::Info("NanoSm", "NanoSm initialized and running successfully.");
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -120,16 +121,14 @@ int main(int argc, char** argv) {
|
||||||
auto tomlTable = toml::parse_file(configPath.string());
|
auto tomlTable = toml::parse_file(configPath.string());
|
||||||
|
|
||||||
if(tomlTable["nanosm"].is_table() && tomlTable["nanosm"]["apps"].is_table()) {
|
if(tomlTable["nanosm"].is_table() && tomlTable["nanosm"]["apps"].is_table()) {
|
||||||
auto restartptr = tomlTable["nanosm"]["restart-time"].as_integer();
|
if(auto restartTimePtr = tomlTable["nanosm"]["restart-time"].as_integer(); !restartTimePtr) {
|
||||||
|
|
||||||
if(!restartptr) {
|
|
||||||
nanosm::log::Warn("NanoSm", "No restart time provided in nanosm.toml. Defaulting to 1 second.");
|
nanosm::log::Warn("NanoSm", "No restart time provided in nanosm.toml. Defaulting to 1 second.");
|
||||||
nanosm.SetRestartTime(1);
|
nanosm.SetRestartTime(1);
|
||||||
} else {
|
} else {
|
||||||
nanosm.SetRestartTime(static_cast<u32>(restartptr->get()));
|
nanosm.SetRestartTime(static_cast<u32>(restartTimePtr->get()));
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto [key, value] : *tomlTable["nanosm"]["apps"].as_table()) {
|
for(auto& [key, value] : *tomlTable["nanosm"]["apps"].as_table()) {
|
||||||
if(!value.is_table()) {
|
if(!value.is_table()) {
|
||||||
nanosm::log::Warn("NanoSm", "Ignoring invalid app \"{}\" in configuration file", key.str());
|
nanosm::log::Warn("NanoSm", "Ignoring invalid app \"{}\" in configuration file", key.str());
|
||||||
continue;
|
continue;
|
||||||
|
@ -149,7 +148,7 @@ int main(int argc, char** argv) {
|
||||||
nanosm.AddApp(std::string(key.data(), key.length()), std::string(cmd.data(), cmd.length()));
|
nanosm.AddApp(std::string(key.data(), key.length()), std::string(cmd.data(), cmd.length()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
nanosm::log::Error("NanoSm", "Configuration file {} doesn't have required values. Exiting with failure.", configPath.string());
|
nanosm::log::Error("NanoSm", "Configuration file {} doesn't have required tables. Exiting with failure.", configPath.string());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue