summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-24 23:04:25 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-24 23:06:16 +0300
commit592000eb84dde8b15e776a1abcf72124aa0f200c (patch)
tree06d9164b49f60a4e584392a5b5b652341892371e /src/cfg
parent3ca328a876f7f4c8bf94c739d2166a1ad1dfb9bc (diff)
Updated README.md, started writing minimal required functions.
Diffstat (limited to 'src/cfg')
-rw-r--r--src/cfg/config.rs73
-rw-r--r--src/cfg/mod.rs1
2 files changed, 74 insertions, 0 deletions
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<Config, toml::de::Error> {
+ let contents = fs::read_to_string("/etc/mesk.toml").unwrap();
+ let result: Config = toml::from_str(&contents)?;
+ Ok(result)
+ }
+
+
+ pub fn default() -> Result<String, toml::ser::Error> {
+ 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