confirm method
Asks question, answered yes (true) or no (false); defaultValue is
what Enter, or an empty line, answers.
Without a default nothing is agreed to on anybody's behalf: Enter
answers nothing until yes or no is chosen, and where nobody can
answer it throws PromptAnswerRequiredException, so a question that
changes something wants a --yes flag for unattended runs.
- CliMode.interactive: the question and the answers of a
ConfirmInput;yandnanswer, Left, Right and Tab move the highlight, Enter answers it.✔ question yesis committed. - CliMode.plain:
? question [Y/n], asked again until the answer isy,yes,nornoin any case, or empty with a default. - CliMode.nonInteractive:
defaultValue, written as? question yes.
Ctrl+C, Ctrl+D and the end of input leave it as they leave prompt.
if (await cli.confirm('Proceed?', defaultValue: true)) {
cli.info('Proceeding.');
}
Implementation
Future<bool> confirm(String question, {bool? defaultValue}) =>
_prompter.confirm(question, defaultValue: defaultValue);