Crates.io | cli-prompts |
lib.rs | cli-prompts |
version | 0.1.0 |
source | src |
created_at | 2023-05-30 19:16:38.995787 |
updated_at | 2023-05-30 19:16:38.995787 |
description | Interactive prompts for the command line |
homepage | |
repository | https://github.com/Melesar/cli-prompts |
max_upload_size | |
id | 878222 |
size | 489,729 |
Create interactive input prompts like in GitHub's CLI tool.
More elaborate examples can be found in the examples directory
use cli_prompts::{
prompts::{Input, AbortReason},
DisplayPrompt
}
fn show_input_prompt() {
let name : Result<String, AbortReason> = Input::new("Enter your name", name_validation)
.default_value("John")
.help_message("Please provide your real name")
.display();
match name {
Ok(n) => println!("The name is {}", n),
Err(abort_reason) => println!("Input was aborted because of {:?}", abort_reason),
}
}
fn name_validation(name: &str) -> Result<String, String> {
if name.len() > 0 {
Ok(name.to_string())
} else {
Err("Name must not be empty".into())
}
}
This project, cli_prompts is licensed under the MIT License - see the LICENSE file for details.