From 7a543409baca98aeb22e81e9ad4b0472d6b4549a Mon Sep 17 00:00:00 2001 From: Bauke Date: Fri, 28 Oct 2022 13:58:36 +0200 Subject: [PATCH] Add the PreCommit hook struct. --- source/config/mod.rs | 5 +++++ source/config/pre_commit.rs | 20 ++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 source/config/pre_commit.rs diff --git a/source/config/mod.rs b/source/config/mod.rs index 20b0f5f..d69d88d 100644 --- a/source/config/mod.rs +++ b/source/config/mod.rs @@ -9,10 +9,12 @@ use { mod exit_action; mod general; +mod pre_commit; mod task; pub use exit_action::*; pub use general::*; +pub use pre_commit::*; pub use task::*; /// The main Hooked configuration struct. @@ -21,6 +23,9 @@ pub use task::*; pub struct Config { /// General Hooked configuration. pub general: General, + + /// Pre-commit hooks. + pub pre_commit: Vec, } impl Config { diff --git a/source/config/pre_commit.rs b/source/config/pre_commit.rs new file mode 100644 index 0000000..ab70316 --- /dev/null +++ b/source/config/pre_commit.rs @@ -0,0 +1,20 @@ +//! Pre-commit hook definitions. + +use serde::{Deserialize, Serialize}; + +use crate::{ExitAction, Task}; + +/// A pre-commit hook. +#[derive(Debug, Deserialize, Serialize)] +#[serde(deny_unknown_fields)] +pub struct PreCommit { + /// Display name for this hook. + pub name: Option, + + /// What to do when the hook exits with a non-zero status code. + pub on_failure: ExitAction, + + /// Task to perform when this hook is called. + #[serde(flatten)] + pub task: Task, +}