From 5819fcc7f983c9705e0226a2e566bff2d0a43585 Mon Sep 17 00:00:00 2001 From: Nareshkumar Rao Date: Fri, 3 May 2024 21:56:09 +0200 Subject: [PATCH] wip --- growpi.service | 1 + src/main.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/growpi.service b/growpi.service index afe8604..6a99318 100644 --- a/growpi.service +++ b/growpi.service @@ -7,6 +7,7 @@ Type=simple Restart=always RestartSec=10 ExecStart=/opt/growpi/growpi +WorkingDirectory=/opt/growpi [Install] WantedBy=mutli-user.target diff --git a/src/main.rs b/src/main.rs index 288ad24..3e636df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,11 +19,16 @@ mod state; fn load_config() -> config::Configuration { let config = Configuration::from_file(std::path::Path::new("./growpi.toml")); - if let Err(config) = &config { - println!("Could not load config: {}", config); + match config { + Ok(config) => config, + Err(_) => { + let config = Configuration::default(); + config + .save_to_file(std::path::Path::new("./growpi.toml")) + .expect("Could not create default config in ./growpi.toml"); + config + } } - - config.unwrap_or_default() } #[tokio::main(flavor = "current_thread")]