pars-core 0.2.4

Pars(a zx2c4-pass compatible passwords manager) core library
Documentation
use std::fmt::{self, Display, Formatter};
use std::path::Path;

pub enum CommitType {
    Init(Vec<String>),
    Insert(String),
    Generate(String),
    Update(String),
    Delete(String),
    Copy((String, String)),
    Rename((String, String)),
}

pub struct GitCommit<'a> {
    repo_base: &'a Path,
    commit_type: CommitType,
}

impl<'a> GitCommit<'a> {
    pub fn new(repo_base: &'a Path, commit_type: CommitType) -> Self {
        Self { repo_base, commit_type }
    }

    pub fn get_commit_msg(&self) -> String {
        match &self.commit_type {
            CommitType::Init(keys) => {
                let mut msg =
                    format!("Init password with {}", keys.first().unwrap_or(&"".to_string()));
                for key in keys[1..].iter() {
                    msg.push_str(&format!(", {key}"));
                }
                msg
            }
            CommitType::Insert(path) => format!("Insert password {path}"),
            CommitType::Generate(path) => format!("Generate password {path}"),
            CommitType::Update(path) => format!("Update password {path}"),
            CommitType::Delete(path) => format!("Delete password {path}"),
            CommitType::Copy((src, dst)) => format!("Copy {src} to {dst}"),
            CommitType::Rename((src, dst)) => format!("Rename {src} to {dst}"),
        }
    }
}

impl Display for GitCommit<'_> {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        write!(f, "{} for repo {}", self.get_commit_msg(), self.repo_base.display())
    }
}