confirm method

bool confirm(
  1. String message, {
  2. bool defaultValue = false,
})

Prompts user with a yes/no question.

Implementation

bool confirm(String message, {bool defaultValue = false}) {
  info(message);

  final input = stdin.readLineSync()?.trim();
  final response = input == null || input.isEmpty
      ? defaultValue
      : input.toBoolean() ?? defaultValue;

  stdout.writeln('$message: ${response ? 'Yes' : 'No'}');

  return response;
}