git_editor/utils/
prompt.rs

1use 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        // We can't easily test interactive input, but we can test that the
32        // function formats the hint correctly
33        let arg_name = "test_arg";
34
35        // This would normally prompt for input, but we can test the format
36        // by checking that the function exists and takes the right parameters
37        assert_eq!(arg_name, "test_arg");
38    }
39
40    #[test]
41    fn test_prompt_functions_exist() {
42        // Test that both prompt functions exist and can be called
43        // (though we can't test interactive behavior in unit tests)
44
45        // These functions exist and have the right signatures
46        let _prompt_fn: fn(&str) -> String = prompt_for_input;
47        let _prompt_missing_fn: fn(&str) -> String = prompt_for_missing_arg;
48    }
49}