chooseOne<T> method
Asks question for one of choices, which must not be empty, each
shown as display makes it (its toString without).
- CliMode.interactive: a
SelectionListof them under the question, seven rows at most: Up and Down move, Enter picks the one the cursor is on, which starts ondefaultValue, or the first. Withfilterwhat is typed narrows the list to the choices it matches (fuzzy, as a command palette does), Backspace takes it back; null filters a list of more than seven. - CliMode.plain: the choices numbered (
1) dev), then a number read, or a choice as it reads; empty,defaultValue, or the first. Any other answer is asked again. - CliMode.nonInteractive:
defaultValue, written as? question choice; adefaultValuethat is not one ofchoices, or none, throws PromptAnswerRequiredException.
Ctrl+C, Ctrl+D (with nothing typed to filter) and the end of input leave it as they leave prompt.
final env = await Cli.current.chooseOne(
'Target environment?',
choices: ['dev', 'stage', 'prod'],
defaultValue: 'dev',
);
Implementation
Future<T> chooseOne<T>(
String question, {
required List<T> choices,
T? defaultValue,
String Function(T choice)? display,
bool? filter,
}) => _prompter.chooseOne(
question,
choices: choices,
defaultValue: defaultValue,
display: display,
filter: filter,
);