Struct requestty::question::ConfirmBuilder [−][src]
pub struct ConfirmBuilder<'a> { /* fields omitted */ }Expand description
Implementations
The message to display when the prompt is rendered in the terminal.
It can be either a String or a FnOnce that returns a String. If it is a
function, it is passed all the previous Answers, and will be called right before the
question is prompted to the user.
If it is not given, the message defaults to “<name>: “.
Examples
use requestty::Question;
let confirm = Question::confirm("anonymous")
.message("Do you want to remain anonymous?")
.build();Whether to ask the question (true) or not (false).
It can be either a bool or a FnOnce that returns a bool. If it is a
function, it is passed all the previous Answers, and will be called right before the
question is prompted to the user.
If it is not given, it defaults to true.
Examples
use requestty::{Question, Answers};
let confirm = Question::confirm("anonymous")
.when(|previous_answers: &Answers| match previous_answers.get("auth") {
Some(ans) => !ans.as_bool().unwrap(),
None => true,
})
.build();Prompt the question even if it is answered.
By default if an answer with the given name already exists, the question will be
skipped. This can be overridden by setting ask_if_answered is set to true.
If this is not given, it defaults to false.
If you need to dynamically decide whether the question should be asked, use when.
Examples
use requestty::Question;
let confirm = Question::confirm("anonymous")
.ask_if_answered(true)
.build();Set a default value for the confirm
If the input text is empty, the default is taken as the answer.
Examples
use requestty::Question;
let confirm = Question::confirm("anonymous")
.default(false)
.build();Change the way the answer looks when displayed to the user.
It is a FnOnce that is given the answer, previous Answers and the Backend to
display the answer on. After the transform is called, a new line is also added.
It will only be called once the user finishes answering the question.
Examples
use requestty::Question;
let confirm = Question::confirm("anonymous")
.transform(|anonymous, previous_answers, backend| {
if anonymous {
write!(backend, "Ok, you are now anonymous!")
} else {
write!(backend, "Please enter your details in the later prompts!")
}
})
.build();Trait Implementations
Consumes the builder returning a Question
