From 592000eb84dde8b15e776a1abcf72124aa0f200c Mon Sep 17 00:00:00 2001 From: Namilskyy Date: Mon, 24 Nov 2025 23:04:25 +0300 Subject: Updated README.md, started writing minimal required functions. --- src/cfg/config.rs | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/cfg/mod.rs | 1 + 2 files changed, 74 insertions(+) create mode 100644 src/cfg/config.rs create mode 100644 src/cfg/mod.rs (limited to 'src/cfg') diff --git a/src/cfg/config.rs b/src/cfg/config.rs new file mode 100644 index 0000000..ee4e3b7 --- /dev/null +++ b/src/cfg/config.rs @@ -0,0 +1,73 @@ +use std::fs; +use std::env; +use serde::{Deserialize, Serialize}; +use toml; + +#[derive(Debug, Deserialize, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Loglevel { + Trace, + Debug, + Info, + Warn, + Error +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct Config { + repo: Repo, + log: Log, + paths: Paths, +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct Log { + logfile: String, + loglevel: Loglevel, +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct Repo { + #[serde(rename = "repo_url")] + repo_url: String, + #[serde(rename = "auto_update")] + auto_update: bool, +} + +#[derive(Deserialize, Debug, Serialize)] +pub struct Paths { + #[serde(rename = "cachedir")] + cachedir: String, + #[serde(rename = "builddir")] + builddir: String, +} + +impl Config { + pub fn parse() -> Result { + let contents = fs::read_to_string("/etc/mesk.toml").unwrap(); + let result: Config = toml::from_str(&contents)?; + Ok(result) + } + + + pub fn default() -> Result { + let default: Config = Config { + repo: Repo { + repo_url: format!("https://mesk.anthrill.i2p/repo/{}/", + std::env::consts::ARCH), + auto_update: true, + }, + log: Log { + logfile: String::from("/var/log/mesk.log"), + loglevel: Loglevel::Info, + }, + paths: Paths { + cachedir: String::from("/var/cache/mesk"), + builddir: String::from("/var/lib/mesk"), + }, + }; + + let toml_str = toml::to_string(&default)?; + Ok(toml_str) + } +} \ No newline at end of file diff --git a/src/cfg/mod.rs b/src/cfg/mod.rs new file mode 100644 index 0000000..b1ca24c --- /dev/null +++ b/src/cfg/mod.rs @@ -0,0 +1 @@ +pub mod config; \ No newline at end of file -- cgit v1.2.3