cleanup toml stuff a bit

This commit is contained in:
Lily Tsuru 2024-02-02 20:43:57 -05:00
parent 0a0ab0703a
commit dcda1bfd1c
1 changed files with 5 additions and 6 deletions

View File

@ -81,6 +81,7 @@ struct NanoSm {
int Run() {
ev.Post([this]() {
this->SpawnAllApps();
nanosm::log::Info("NanoSm", "NanoSm initialized and running successfully.");
});
try {
@ -120,16 +121,14 @@ int main(int argc, char** argv) {
auto tomlTable = toml::parse_file(configPath.string());
if(tomlTable["nanosm"].is_table() && tomlTable["nanosm"]["apps"].is_table()) {
auto restartptr = tomlTable["nanosm"]["restart-time"].as_integer();
if(!restartptr) {
if(auto restartTimePtr = tomlTable["nanosm"]["restart-time"].as_integer(); !restartTimePtr) {
nanosm::log::Warn("NanoSm", "No restart time provided in nanosm.toml. Defaulting to 1 second.");
nanosm.SetRestartTime(1);
} 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()) {
nanosm::log::Warn("NanoSm", "Ignoring invalid app \"{}\" in configuration file", key.str());
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()));
}
} 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;
}