tci/src/config.rs

55 lines
1 KiB
Rust
Raw Normal View History

2024-02-14 20:06:49 +01:00
#[derive(Debug, Default, serde::Deserialize)]
2024-02-15 03:04:53 +01:00
pub struct TciConfig {
2024-02-14 20:06:49 +01:00
#[serde(default)]
pub allow_all: bool,
#[serde(default)]
2024-02-15 03:04:53 +01:00
pub branch: Option<String>,
2024-02-14 20:06:49 +01:00
#[serde(default)]
2024-02-15 03:04:53 +01:00
pub hooks: Vec<String>,
2024-02-14 20:06:49 +01:00
#[serde(default)]
pub setup: Vec<String>,
#[serde(default)]
pub cleanup: Vec<String>,
}
2024-02-15 03:04:53 +01:00
impl TciConfig {
pub fn load() -> Result<Self, toml::de::Error> {
let config_path = std::env::var("TCI_CONFIG")
.as_deref()
.unwrap_or("/etc/tci/config.toml");
let cfg_raw = std::fs::read_to_string(config_path)
.unwrap_or_default();
toml::from_str(&cfg_raw)
}
}
2024-02-14 20:06:49 +01:00
#[derive(Debug, Default, serde::Deserialize)]
pub struct TciScriptConfig {
#[serde(default)]
pub branch: Option<String>,
#[serde(default)]
pub filter: Option<String>,
#[serde(default)]
2024-02-15 03:04:53 +01:00
pub scripts: Vec<String>,
2024-02-14 20:06:49 +01:00
// #[serde(default)]
// concurrent: bool,
}
2024-02-15 03:04:53 +01:00
impl TciScriptConfig {
pub fn load(path: &std::path::PathBuf) -> Result<Self, toml::de::Error> {
let cfg_raw = std::fs::read_to_string(path)
.unwrap_or_default();
toml::from_str(&cfg_raw)
}
}