11个版本
0.0.11 | 2019年12月12日 |
---|---|
0.0.10 | 2019年2月22日 |
0.0.9 | 2018年10月31日 |
#3 在 #question
每月 33 次下载
30KB
519 行
Ask
一个简单的通过终端提问的工具集。
用法
extern crate ask;
use ask::question::{MultipleChoice, OptionGroup, TraitQuestion, QuestionOption};
use ask::validate;
fn main() {
let mut multiple_choice = MultipleChoice::new("What would you like to order?".to_owned());
let answer_collections = multiple_choice
.add_option_group(
OptionGroup::new("Entrees")
.add_option_by_str("Calamari".to_owned())
.add_option_by_str("Buffalo wings".to_owned())
.add_option_by_str("Shrimp".to_owned())
)
.add_option_group(
OptionGroup::new("Main Course")
.add_option(QuestionOption::new("Lobster".to_owned()))
.add_option(QuestionOption::new("T-Bone".to_owned()).toggle_selected(None))//toggle the selected to opposite to what it currently is
.add_option(QuestionOption::new("Burger".to_owned()).toggle_selected(Some(false)))
.add_option(QuestionOption::new("Duck".to_owned()).toggle_selected(Some(true))) //set this option to be selected by default asking the question
)
.set_validation(Box::new(|answer_collection| {
validate::group_options::selections_are_gtoe(& answer_collection, 1) &&
validate::group_options::selections_are_ltoe(& answer_collection, 1)
})
)
// .replace_continue_btn("CAN CONTINUE!!".to_owned(), "CANNOT CONTINUE!!".to_owned()) //can customize continue btn
.send()
.unwrap();
println!("");
// let answer_collections = multiple_choice.to_answer_collections(); //can pull the answer_collections at any time
for answer_sets in answer_collections.answer_sets{
for answer in answer_sets.answers{
println!("{}", answer);
}
}
应该显示
依赖
~2.3–3.5MB
~57K SLoC