hooked/hooked-config/source/config/mod.rs

40 lines
777 B
Rust
Raw Normal View History

2022-10-28 10:23:05 +00:00
//! Configuration structs and logic.
use std::{fs::read_to_string, path::Path};
use {
color_eyre::Result,
serde::{Deserialize, Serialize},
};
2022-10-28 11:35:34 +00:00
mod exit_action;
2022-10-28 10:23:05 +00:00
mod general;
2022-10-28 11:58:36 +00:00
mod pre_commit;
2022-10-28 11:13:53 +00:00
mod task;
2022-10-28 10:23:05 +00:00
2022-10-28 11:35:34 +00:00
pub use exit_action::*;
2022-10-28 10:23:05 +00:00
pub use general::*;
2022-10-28 11:58:36 +00:00
pub use pre_commit::*;
2022-10-28 11:13:53 +00:00
pub use task::*;
2022-10-28 10:23:05 +00:00
/// The main Hooked configuration struct.
#[derive(Debug, Default, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct Config {
/// General Hooked configuration.
pub general: General,
2022-10-28 11:58:36 +00:00
/// Pre-commit hooks.
pub pre_commit: Vec<PreCommit>,
2022-10-28 10:23:05 +00:00
}
impl Config {
/// Read a file and parse it with [`toml`].
pub fn from_toml_file<P>(file: P) -> Result<Self>
where
P: AsRef<Path>,
{
toml::from_str(&read_to_string(file)?).map_err(Into::into)
}
}