~/selfhut

selfhut/src/utils/repo_config.rs -rw-r--r-- 766 B
00c0a257 — Arthur Melton format code 2 years ago

            
f1a6543a Arthur Melton
532ca616 Arthur Melton
ef55c0da arthurmelton
0016c2cc arthurmelton
532ca616 Arthur Melton
ef55c0da arthurmelton
f1a6543a Arthur Melton
ef55c0da arthurmelton
00c0a257 Arthur Melton
ef55c0da arthurmelton














1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use crate::config::CONFIG;
use serde_derive::{Deserialize, Serialize};
use std::fs;

pub fn repo_config(repo: String) -> RepoConfig {
    let mut config = CONFIG.git_location.clone();
    config.push(format!("{}.git", repo));
    config.push("repo.toml");
    let config_string = match fs::read(config) {
        Ok(content) => String::from_utf8_lossy(&content)
            .parse()
            .unwrap_or("".to_string()),
        Err(_) => "".to_string(),
    };
    match toml::from_str(&config_string) {
        Ok(x) => x,
        Err(_) => RepoConfig {
            description: None,
            website: None,
        },
    }
}

#[derive(Deserialize, Serialize)]
pub struct RepoConfig {
    pub description: Option<String>,
    pub website: Option<String>,
}