git_revise/revise/prompts/
commit_scope.rs1use inquire::{Select, Text};
2
3use super::Inquire;
4use crate::{
5 config::{self},
6 error::ReviseResult,
7};
8
9#[derive(Debug, Clone)]
10pub struct Part {
11 pub msg: String,
12 pub ans: Option<String>,
13 pub options: Vec<String>,
14}
15
16impl Part {
17 pub fn new() -> Self {
18 let cfg = config::get_config();
19 let mut options: Vec<String> = cfg.get_scopes();
20 if !options.contains(&"empty".to_string()) {
22 options.insert(0, "empty".to_string());
23 }
24
25 if !options.contains(&"custom".to_string()) {
27 options.push("custom".to_string());
28 }
29
30 Self {
31 msg: "Denote the SCOPE of this change (optional):".to_string(),
32 ans: None,
33 options,
34 }
35 }
36}
37
38impl Default for Part {
39 fn default() -> Self {
40 Self::new()
41 }
42}
43
44impl Inquire for Part {
45 fn inquire(&mut self) -> ReviseResult<()> {
46 let mut ans = Select::new(&self.msg, self.options.clone()).prompt()?;
47
48 if ans == "custom" {
49 ans = Text::new("Denote the SCOPE of this change:").prompt()?;
50 self.ans = Some(ans).filter(|a| !a.is_empty());
51 } else if ans == "empty" {
52 self.ans = None;
53 } else {
54 self.ans = Some(ans);
55 };
56 Ok(())
57 }
58}