Read settings
This commit is contained in:
parent
a32745b1bc
commit
14ebe00d42
4 changed files with 1064 additions and 6 deletions
1013
Cargo.lock
generated
1013
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,4 +6,8 @@ author = "Martin Brodbeck <info@rustysoft.de>"
|
|||
|
||||
[dependencies]
|
||||
config = { version = "0.13.4", features = ["yaml"] }
|
||||
home = "0.5.5"
|
||||
reqwest = "0.11.22"
|
||||
serde = { version = "1.0.193", features = ["serde_derive"] }
|
||||
serde_derive = "1.0.193"
|
||||
|
||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,7 +1,16 @@
|
|||
mod settings;
|
||||
|
||||
use settings::Settings;
|
||||
|
||||
fn main() {
|
||||
|
||||
let settings = Settings::new();
|
||||
let settings = match settings {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
println!("Could not read settings. Please provide the settings file 'clrigctl.toml'.");
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
println!("{:?}", settings);
|
||||
}
|
||||
|
||||
|
||||
|
|
38
src/settings.rs
Normal file
38
src/settings.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use config::{Config, ConfigError, File};
|
||||
use home;
|
||||
use serde_derive::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[allow(unused)]
|
||||
struct Cloudlog {
|
||||
url: String,
|
||||
key: String,
|
||||
identifier: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[allow(unused)]
|
||||
struct Flrig {
|
||||
host: String,
|
||||
port: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[allow(unused)]
|
||||
pub struct Settings {
|
||||
cloudlog: Cloudlog,
|
||||
flrig: Flrig,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
pub fn new() -> Result<Self, ConfigError> {
|
||||
let mut config_file = home::home_dir().unwrap().into_os_string();
|
||||
config_file.push("/.config/clrigctl.toml");
|
||||
|
||||
let settings = Config::builder()
|
||||
.add_source(File::with_name(config_file.to_str().unwrap()))
|
||||
.build()?;
|
||||
|
||||
settings.try_deserialize()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue