Add config deserialization
Co-authored-by: Elias Schriefer
This commit is contained in:
parent
9b4246a078
commit
b04b61adbd
11
Cargo.lock
generated
11
Cargo.lock
generated
@ -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"
|
||||
|
@ -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"]
|
||||
|
22
src/main.rs
22
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user