(prompt: &str, default: Option<&str>)
| 141 | Ok(matches!(answer.as_str(), "y" | "yes")) |
| 142 | } |
| 143 | |
| 144 | pub(crate) fn prompt_text(prompt: &str, default: Option<&str>) -> Result<String, String> { |
| 145 | print!("{prompt}"); |
| 146 | io::stdout() |
| 147 | .flush() |
| 148 | .map_err(|err| format!("failed to flush prompt: {err}"))?; |
| 149 | let mut input = String::new(); |
| 150 | io::stdin() |
| 151 | .read_line(&mut input) |
| 152 | .map_err(|err| format!("failed to read input: {err}"))?; |
| 153 | let trimmed = input.trim(); |
| 154 | if trimmed.is_empty() { |
| 155 | return Ok(default.unwrap_or("").to_string()); |
| 156 | } |
| 157 | Ok(trimmed.to_string()) |
| 158 | } |
| 159 | |
| 160 | pub(crate) fn scripts_command(args: &[String], cwd: &Path) -> Result<(), String> { |
no test coverage detected