45 lines
859 B
Rust
45 lines
859 B
Rust
use std::sync::Arc;
|
|
|
|
use file::parse_config;
|
|
use serde::Deserialize;
|
|
|
|
use crate::utils::Error;
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct Settings {
|
|
pub subsonic: Subsonic,
|
|
#[serde(default = "default_controls")]
|
|
pub controls: Controls,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct Subsonic {
|
|
pub server_address: String,
|
|
pub username: String,
|
|
#[serde(default)]
|
|
pub password: String, // Only optional in file, will otherwise pull from Env var
|
|
#[serde(default = "default_random_limit")]
|
|
pub random_limit: i32,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
pub struct Controls {
|
|
pub quit: char,
|
|
}
|
|
|
|
fn default_controls() -> Controls {
|
|
Controls { quit: 'q' }
|
|
}
|
|
|
|
fn default_random_limit() -> i32 {
|
|
10
|
|
}
|
|
|
|
pub fn init() -> Result<Arc<Settings>, Error> {
|
|
let settings = parse_config()?;
|
|
Ok(Arc::new(settings))
|
|
}
|
|
|
|
mod errors;
|
|
mod file;
|
|
mod validate;
|