mit_commit_message_lints/mit/lib/
non_clean_behaviour.rs

1//! Differing behaviours on rebase
2use std::{
3    fmt::{Display, Formatter},
4    str::FromStr,
5};
6
7use crate::mit::lib::errors::DeserializeRebaseBehaviourError;
8
9/// Differing behaviours on non-clean repository
10#[derive(clap::ValueEnum, Ord, PartialOrd, Eq, PartialEq, Debug, Clone, Copy)]
11pub enum BehaviourOption {
12    /// Change the commit message to include the current author
13    AddTo,
14    /// Do not change the commit message
15    NoChange,
16}
17
18const ADD_TO_DISPLAY: &str = "add-to";
19const NO_CHANGE_DISPLAY: &str = "no-change";
20
21impl FromStr for BehaviourOption {
22    type Err = DeserializeRebaseBehaviourError;
23
24    fn from_str(s: &str) -> Result<Self, Self::Err> {
25        match s {
26            ADD_TO_DISPLAY => Ok(Self::AddTo),
27            NO_CHANGE_DISPLAY => Ok(Self::NoChange),
28            _ => Err(DeserializeRebaseBehaviourError { src: s.into() }),
29        }
30    }
31}
32
33impl Display for BehaviourOption {
34    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
35        match self {
36            Self::AddTo => write!(f, "{ADD_TO_DISPLAY}"),
37            Self::NoChange => write!(f, "{NO_CHANGE_DISPLAY}"),
38        }
39    }
40}