Add configs
This commit is contained in:
parent
85891abba0
commit
208eed348b
6
config/main.template.toml
Normal file
6
config/main.template.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
seperator=" | "
|
||||
|
||||
[plugins]
|
||||
blacklist=["example_c", "example_rust"]
|
||||
as_whitelist=false
|
||||
template=["counter", "battery", "clock"]
|
6
config/main.toml
Normal file
6
config/main.toml
Normal file
|
@ -0,0 +1,6 @@
|
|||
seperator=" | "
|
||||
|
||||
[plugins]
|
||||
blacklist=["example_c", "example_rust"]
|
||||
as_whitelist=false
|
||||
template=["counter", "battery", "clock"]
|
55
src/config.rs
Normal file
55
src/config.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct Config {
|
||||
pub seperator: String,
|
||||
pub plugins: ConfigPlugins,
|
||||
|
||||
#[serde(skip)]
|
||||
pub config_dir: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||
pub struct ConfigPlugins {
|
||||
pub blacklist: Vec<String>,
|
||||
pub as_whitelist: bool,
|
||||
pub template: Vec<String>,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(path: &Path) -> Result<Self, ConfigError> {
|
||||
let path = path.join("main.toml");
|
||||
|
||||
if !path.exists() {
|
||||
println!("ERROR: {:?} doesnt exist", path);
|
||||
}
|
||||
|
||||
let mut cfg: Self = toml::from_str(
|
||||
&std::fs::read_to_string(&path)?
|
||||
)?;
|
||||
|
||||
cfg.config_dir = path.to_path_buf();
|
||||
Ok(cfg)
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum ConfigError {
|
||||
IoError(std::io::Error),
|
||||
TomlDeserialiseError(toml::de::Error)
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ConfigError {
|
||||
fn from(e: std::io::Error) -> Self {
|
||||
Self::IoError(e)
|
||||
}
|
||||
}
|
||||
impl From<toml::de::Error> for ConfigError {
|
||||
fn from(e: toml::de::Error) -> Self {
|
||||
Self::TomlDeserialiseError(e)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user