promptRequired method

String promptRequired(
  1. String message, {
  2. String? defaultValue,
  3. String? errorMessage,
})

Prompts the user for a non-empty string value.

Implementation

String promptRequired(
  String message, {
  String? defaultValue,
  String? errorMessage,
}) {
  if (!_interactive) {
    throw FormatException(
      errorMessage ??
          'Interactive input is unavailable. Pass the required option explicitly.',
    );
  }

  while (true) {
    _out.write(
      cliInfo(
        defaultValue == null ? '$message: ' : '$message [$defaultValue]: ',
        ansiEnabled: _ansiEnabled,
      ),
    );
    final response = _readLine()?.trim();
    if (response != null && response.isNotEmpty) {
      return response;
    }
    if (defaultValue != null && defaultValue.isNotEmpty) {
      return defaultValue;
    }
  }
}