1use std::fmt::{self, Display, Formatter};
2use std::path::Path;
3
4pub enum CommitType {
5 Init(Vec<String>),
6 Insert(String),
7 Generate(String),
8 Update(String),
9 Delete(String),
10 Copy((String, String)),
11 Rename((String, String)),
12}
13
14pub struct GitCommit<'a> {
15 repo_base: &'a Path,
16 commit_type: CommitType,
17}
18
19impl<'a> GitCommit<'a> {
20 pub fn new(repo_base: &'a Path, commit_type: CommitType) -> Self {
21 Self { repo_base, commit_type }
22 }
23
24 pub fn get_commit_msg(&self) -> String {
25 match &self.commit_type {
26 CommitType::Init(keys) => {
27 let mut msg =
28 format!("Init password with {}", keys.first().unwrap_or(&"".to_string()));
29 for key in keys[1..].iter() {
30 msg.push_str(&format!(", {}", key));
31 }
32 msg
33 }
34 CommitType::Insert(path) => format!("Insert password {}", path),
35 CommitType::Generate(path) => format!("Generate password {}", path),
36 CommitType::Update(path) => format!("Update password {}", path),
37 CommitType::Delete(path) => format!("Delete password {}", path),
38 CommitType::Copy((src, dst)) => format!("Copy {} to {}", src, dst),
39 CommitType::Rename((src, dst)) => format!("Rename {} to {}", src, dst),
40 }
41 }
42}
43
44impl Display for GitCommit<'_> {
45 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
46 write!(f, "{} for repo {}", self.get_commit_msg(), self.repo_base.display())
47 }
48}