pre_commit_sort/
local.rs

1/// ref. <https://pre-commit.com/#repository-local-hooks>
2use crate::DeclareHook;
3
4#[serde_with::skip_serializing_none]
5#[derive(serde::Serialize, serde::Deserialize, Debug, Eq, Ord, PartialEq, PartialOrd, Clone)]
6pub struct Local {
7    repo: String,
8    hooks: Vec<DeclareHook>,
9}
10
11impl Local {
12    #[must_use]
13    pub fn new() -> Self {
14        Self {
15            repo: String::from("local"),
16            hooks: Vec::new(),
17        }
18    }
19
20    pub fn add_hook(&mut self, hook: DeclareHook) {
21        self.hooks.push(hook);
22    }
23
24    pub fn sort(&mut self) {
25        self.hooks.sort();
26        self.hooks.dedup();
27    }
28}
29
30impl Default for Local {
31    fn default() -> Self {
32        Self::new()
33    }
34}