subtails/src/config/mod.rs

46 lines
859 B
Rust
Raw Normal View History

2024-11-25 14:57:49 +05:00
use std::sync::Arc;
2024-11-25 16:16:43 +05:00
use file::parse_config;
use serde::Deserialize;
2024-11-25 14:57:49 +05:00
use crate::utils::Error;
2024-11-25 16:16:43 +05:00
#[derive(Deserialize)]
pub struct Settings {
pub subsonic: Subsonic,
2024-11-28 12:16:58 +05:00
#[serde(default = "default_controls")]
pub controls: Controls,
2024-11-25 16:16:43 +05:00
}
#[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
2024-11-27 16:01:29 +05:00
#[serde(default = "default_random_limit")]
pub random_limit: i32,
}
2024-11-28 12:16:58 +05:00
#[derive(Deserialize)]
pub struct Controls {
pub quit: char,
}
fn default_controls() -> Controls {
Controls { quit: 'q' }
}
2024-11-27 16:01:29 +05:00
fn default_random_limit() -> i32 {
10
2024-11-25 16:16:43 +05:00
}
2024-11-25 14:57:49 +05:00
pub fn init() -> Result<Arc<Settings>, Error> {
2024-11-25 16:16:43 +05:00
let settings = parse_config()?;
Ok(Arc::new(settings))
2024-11-25 14:57:49 +05:00
}
2024-11-25 16:16:43 +05:00
mod errors;
mod file;
mod validate;