getString function

String getString(
  1. ArgResults results,
  2. String name,
  3. String message, {
  4. required bool isInteractive,
  5. String? desc,
})

Implementation

String getString(
  ArgResults results,
  String name,
  String message, {
  required bool isInteractive,
  String? desc,
}) {
  var value = results[name] as String?;
  if (!isInteractive) {
    if (value == null || value.isEmpty) {
      print('Missing parameter $name is required.');
      exit(1);
    }
  }
  while (value == null || value.isEmpty) {
    if (desc != null) {
      stdout.write(ansi.darkGray.wrap('\n$desc\u{1B}[1A\r'));
    }
    value = prompts.get(message, validate: (it) => !it.contains('-'));
    if (desc != null) {
      stdout.write('\r\u{1B}[K');
    }
  }
  return value;
}