hooked_config/config/
mod.rs

1//! Configuration structs and logic.
2
3use std::{fs::read_to_string, path::Path};
4
5use {
6  color_eyre::Result,
7  serde::{Deserialize, Serialize},
8};
9
10mod exit_action;
11mod general;
12mod pre_commit;
13mod task;
14
15pub use exit_action::*;
16pub use general::*;
17pub use pre_commit::*;
18pub use task::*;
19
20/// The main Hooked configuration struct.
21#[derive(Debug, Default, Deserialize, Serialize)]
22#[serde(default, deny_unknown_fields)]
23pub struct Config {
24  /// General Hooked configuration.
25  pub general: General,
26
27  /// Pre-commit hooks.
28  pub pre_commit: Vec<PreCommit>,
29}
30
31impl Config {
32  /// Read a file and parse it with [`toml`].
33  pub fn from_toml_file<P>(file: P) -> Result<Self>
34  where
35    P: AsRef<Path>,
36  {
37    toml::from_str(&read_to_string(file)?).map_err(Into::into)
38  }
39}