Add config deserialization

Co-authored-by: Elias Schriefer
This commit is contained in:
Erik Foris 2021-06-08 13:57:04 +00:00
parent 9b4246a078
commit b04b61adbd
3 changed files with 34 additions and 1 deletions

11
Cargo.lock generated
View File

@ -1206,8 +1206,10 @@ dependencies = [
"juniper", "juniper",
"juniper-from-schema", "juniper-from-schema",
"juniper_warp", "juniper_warp",
"serde",
"sqlx", "sqlx",
"structopt", "structopt",
"toml",
"warp 0.3.1", "warp 0.3.1",
] ]
@ -2157,6 +2159,15 @@ dependencies = [
"tokio 1.5.0", "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]] [[package]]
name = "tower-service" name = "tower-service"
version = "0.3.1" version = "0.3.1"

View File

@ -14,6 +14,8 @@ juniper-from-schema = { git = "https://github.com/davidpdrsn/juniper-from-schema
sqlx = { version = "^0.5", features = ["runtime-tokio-native-tls"] } sqlx = { version = "^0.5", features = ["runtime-tokio-native-tls"] }
warp = { version = "^0.3", default-features = false, features = ["compression", "tls"] } warp = { version = "^0.3", default-features = false, features = ["compression", "tls"] }
structopt = { version = "^0.3", features = ["wrap_help"] } structopt = { version = "^0.3", features = ["wrap_help"] }
toml = "^0.5"
serde = { version = "^1.0", features = ["derive"] }
[features] [features]
default = ["sqlite"] default = ["sqlite"]

View File

@ -1,15 +1,35 @@
use structopt::StructOpt; use structopt::StructOpt;
use std::path::PathBuf; use std::path::PathBuf;
use serde::Deserialize;
const DEFAULT_DATABASE_PATH: &'static str = "/var/lib/noise-server/noise-server.sqlite";
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct Options { struct Options {
#[structopt(short, long, default_value = "/etc/noise-server/config.toml")] #[structopt(short, long, default_value = "/etc/noise-server/config.toml")]
config: PathBuf, 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, 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() { fn main() {
let options = Options::from_args(); let options = Options::from_args();
#[cfg(debug_assertions)]
println!("{:?}", options);
} }