git_revise/revise/prompts/
commit_translate.rs

1use inquire::{
2    validator::{ErrorMessage, Validation},
3    Text,
4};
5
6use super::Inquire;
7use crate::error::ReviseResult;
8
9#[derive(Debug, Clone)]
10pub struct Part {
11    pub msg: String,
12    pub ans: Option<String>,
13}
14
15impl Part {
16    pub fn new() -> Self {
17        Self {
18            msg: "Input the commit message you want to translate:\n"
19                .to_string(),
20            ans: None,
21        }
22    }
23}
24
25impl Default for Part {
26    fn default() -> Self {
27        Self::new()
28    }
29}
30
31impl Inquire for Part {
32    fn inquire(&mut self) -> ReviseResult<()> {
33        let ans = Text::new(&self.msg)
34            .with_validator(|s: &str| {
35                if s.is_empty() {
36                    return Ok(Validation::Invalid(ErrorMessage::Custom(
37                        "[ERROR] Subject is required and cannot be empty"
38                            .to_string(),
39                    )));
40                }
41                Ok(Validation::Valid)
42            })
43            .prompt()?;
44        self.ans = Some(ans);
45        Ok(())
46    }
47}