git_editor/utils/
prompt.rs1use colored::*;
2use std::io::{self, Write};
3
4pub fn prompt_for_input(prompt: &str) -> String {
5 print!("{prompt}: ");
6 io::stdout().flush().expect("Failed to flush stdout");
7
8 let mut input = String::new();
9 io::stdin()
10 .read_line(&mut input)
11 .expect("Failed to read line");
12
13 input.trim().to_string()
14}
15
16pub fn prompt_for_missing_arg(arg_name: &str) -> String {
17 let hint = format!(
18 "{} '{}'",
19 "Please provide a value for".yellow(),
20 arg_name.yellow().bold()
21 );
22 prompt_for_input(&hint)
23}
24
25#[cfg(test)]
26mod tests {
27 use super::*;
28
29 #[test]
30 fn test_prompt_for_missing_arg_formats_correctly() {
31 let arg_name = "test_arg";
34
35 assert_eq!(arg_name, "test_arg");
38 }
39
40 #[test]
41 fn test_prompt_functions_exist() {
42 let _prompt_fn: fn(&str) -> String = prompt_for_input;
47 let _prompt_missing_fn: fn(&str) -> String = prompt_for_missing_arg;
48 }
49}