summaryrefslogtreecommitdiff
path: root/src/cfg
diff options
context:
space:
mode:
authorNamilskyy <alive6863@gmail.com>2025-11-25 16:50:59 +0300
committerNamilskyy <alive6863@gmail.com>2025-11-25 16:50:59 +0300
commit778f713b2c4b8f8311daf2b878de91e449f69988 (patch)
tree020af9cb8ea6e78a2edca31879c94cf50942f50e /src/cfg
parent296b5dc8473fe2e0fe39ec94b9e5109aa7857774 (diff)
Created minimal package validation here. Writed documentations comments (///)
Diffstat (limited to 'src/cfg')
-rw-r--r--src/cfg/config.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/cfg/config.rs b/src/cfg/config.rs
index 45be37d..8672433 100644
--- a/src/cfg/config.rs
+++ b/src/cfg/config.rs
@@ -13,39 +13,45 @@ pub enum Loglevel {
Error
}
+
+/// `mesk.toml` configuration fields here
#[derive(Deserialize, Debug, Serialize)]
pub struct Config {
- repo: Repo,
- log: Log,
- paths: Paths,
+ pub repo: Repo,
+ pub log: Log,
+ pub paths: Paths,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct Log {
#[serde(rename = "log_file")]
- log_file: String,
+ pub log_file: String,
#[serde(rename = "log_level")]
- log_level: Loglevel,
+ pub log_level: Loglevel,
}
// Rename needed for editing mesk.toml file fields but dont touch code.
#[derive(Deserialize, Debug, Serialize)]
pub struct Repo {
#[serde(rename = "repo_url")]
- repo_url: String,
+ pub repo_url: String,
#[serde(rename = "auto_update")]
- auto_update: bool,
+ pub auto_update: bool,
}
#[derive(Deserialize, Debug, Serialize)]
pub struct Paths {
#[serde(rename = "cache_dir")]
- cache_dir: String,
+ pub cache_dir: String,
#[serde(rename = "build_dir")]
- build_dir: String,
+ pub build_dir: String,
}
impl Config {
+
+ /// Parse the /etc/mesk.toml file and return the Config object.
+ ///
+ /// This function reads the /etc/mesk.toml file, parses it and returns the Config object.
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)?;
@@ -53,6 +59,9 @@ impl Config {
}
+ /// Return the default configuration as a toml string.
+ ///
+ /// This function returns the default configuration as a toml string.
pub fn default() -> Result<String, toml::ser::Error> {
let default: Config = Config {
repo: Repo {