forked from Lutetium-Vanadium/requestty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti-select.rs
More file actions
31 lines (29 loc) · 1004 Bytes
/
multi-select.rs
File metadata and controls
31 lines (29 loc) · 1004 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use requestty::{Choice, Separator};
fn main() {
let question = requestty::Question::multi_select("toppings")
.message("Select toppings")
.separator(" = The Meats = ")
.choices(vec!["Pepperoni", "Ham", "Ground Meat", "Bacon"])
.separator(" = The Cheeses = ")
.choice_with_default("Mozzarella", true)
.choice("Cheddar")
.choices(vec![
Choice("Parmesan".into()),
Separator(" = The usual = ".into()),
"Mushroom".into(),
"Tomato".into(),
Separator(" = The extras = ".into()),
"Pineapple".into(),
"Olives".into(),
"Extra cheese".into(),
])
.validate(|answer, _| {
if answer.iter().filter(|&&a| a).count() < 1 {
Err("You must choose at least one topping.".into())
} else {
Ok(())
}
})
.build();
println!("{:#?}", requestty::prompt_one(question));
}