2023-06-07 02:02:58 +00:00
|
|
|
use std::{
|
|
|
|
|
io::{Error, ErrorKind},
|
|
|
|
|
path::PathBuf,
|
|
|
|
|
};
|
2023-06-05 22:18:10 +00:00
|
|
|
|
|
|
|
|
use filenamify::filenamify;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
2023-06-07 02:02:58 +00:00
|
|
|
use crate::path::{config_file, repositories_dir};
|
2023-06-05 03:08:43 +00:00
|
|
|
|
|
|
|
|
#[derive(Deserialize)]
|
|
|
|
|
pub struct Config {
|
|
|
|
|
pub repositories: Vec<Repository>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Config {
|
2023-06-07 02:02:58 +00:00
|
|
|
pub fn load() -> Result<Self, Error> {
|
|
|
|
|
let file = serdeconv::from_toml_file(crate::path::config_file().as_path());
|
|
|
|
|
file.map_err(|_| {
|
|
|
|
|
Error::new(
|
|
|
|
|
ErrorKind::InvalidData,
|
|
|
|
|
format!("Config {:?} doesn't exist or is not valid", config_file()),
|
|
|
|
|
)
|
|
|
|
|
})
|
2023-06-05 03:08:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-05 22:18:10 +00:00
|
|
|
#[derive(Deserialize)]
|
2023-06-05 03:08:43 +00:00
|
|
|
pub struct Repository {
|
|
|
|
|
pub git_url: String,
|
|
|
|
|
}
|
2023-06-05 22:18:10 +00:00
|
|
|
|
|
|
|
|
impl Repository {
|
|
|
|
|
pub fn dir(&self) -> PathBuf {
|
|
|
|
|
repositories_dir().join(filenamify(&self.git_url))
|
|
|
|
|
}
|
|
|
|
|
}
|