From b04b61adbdd800df5b3e15cd3447b723977e0da7 Mon Sep 17 00:00:00 2001 From: erik Date: Tue, 8 Jun 2021 13:57:04 +0000 Subject: [PATCH] Add config deserialization Co-authored-by: Elias Schriefer --- Cargo.lock | 11 +++++++++++ Cargo.toml | 2 ++ src/main.rs | 22 +++++++++++++++++++++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 65f9511..ea39be3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1206,8 +1206,10 @@ dependencies = [ "juniper", "juniper-from-schema", "juniper_warp", + "serde", "sqlx", "structopt", + "toml", "warp 0.3.1", ] @@ -2157,6 +2159,15 @@ dependencies = [ "tokio 1.5.0", ] +[[package]] +name = "toml" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 522cba5..d180202 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,8 @@ juniper-from-schema = { git = "https://github.com/davidpdrsn/juniper-from-schema sqlx = { version = "^0.5", features = ["runtime-tokio-native-tls"] } warp = { version = "^0.3", default-features = false, features = ["compression", "tls"] } structopt = { version = "^0.3", features = ["wrap_help"] } +toml = "^0.5" +serde = { version = "^1.0", features = ["derive"] } [features] default = ["sqlite"] diff --git a/src/main.rs b/src/main.rs index 0411239..08e7a9a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,35 @@ use structopt::StructOpt; use std::path::PathBuf; +use serde::Deserialize; + +const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite"; #[derive(Debug, StructOpt)] struct Options { #[structopt(short, long, default_value = "/etc/noise-server/config.toml")] config: PathBuf, - #[structopt(short, long, default_value = "/var/lib/noise-server/noise-server.sqlite")] + #[structopt(short, long, default_value = DEFAULT_DATABASE_PATH)] database_path: PathBuf, } +#[derive(Debug, Deserialize)] +#[serde(default)] +struct Config { + database_path: PathBuf, + +} + +impl Default for Config { + fn default() -> Self { + Config { + database_path: DEFAULT_DATABASE_PATH.into(), + } + } +} + fn main() { let options = Options::from_args(); + #[cfg(debug_assertions)] + println!("{:?}", options); }