first commit
This commit is contained in:
38
main.rs
Normal file
38
main.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use inquire::{Text, validator::{Validation}};
|
||||
use inquire::{error::InquireError, Select};
|
||||
use regex::Regex;
|
||||
|
||||
fn main() {
|
||||
let re = Regex::new(r"CHG[0-9]{6}$").unwrap();
|
||||
let options: Vec<&str> = vec!["File change", "Package Update", "Package Removal",
|
||||
"File Removal", "Misc. Command"];
|
||||
|
||||
let change_validator = move |input: &str| if input.chars().count() == 0 {
|
||||
Ok(Validation::Invalid("Change request cannot be empty".into()))
|
||||
} else if re.is_match(input) {
|
||||
Ok(Validation::Valid)
|
||||
} else {
|
||||
Ok(Validation::Invalid("Invalid change request (e.g: CHGXXXXXX)".into()))
|
||||
};
|
||||
|
||||
let validator = |input: &str| if input.chars().count() > 140 {
|
||||
Ok(Validation::Invalid("You're only allowed 140 characters.".into()))
|
||||
} else if input.chars().count() == 0 {
|
||||
Ok(Validation::Invalid("".into()))
|
||||
} else {
|
||||
Ok(Validation::Valid)
|
||||
};
|
||||
|
||||
let _ = Text::new("system prompt $ ")
|
||||
.with_validator(validator)
|
||||
.prompt();
|
||||
|
||||
let _ = Text::new("(e.g. CHGXXXXXX) Enter change request: ").with_validator(change_validator).prompt();
|
||||
|
||||
let ans: Result<&str, InquireError> = Select::new("Change Type?", options).prompt();
|
||||
|
||||
match ans {
|
||||
Ok(_) => println!("running command..."),
|
||||
Err(_) => println!("not running command..."),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user