getMultiOption function

List<String> getMultiOption(
  1. ArgResults results,
  2. String name,
  3. String message,
  4. List<String> options, {
  5. required bool isInteractive,
  6. required bool isRequired,
  7. List<String> startingOptions = const [],
  8. String? desc,
})

Implementation

List<String> getMultiOption(
  ArgResults results,
  String name,
  String message,
  List<String> options, {
  required bool isInteractive,
  required bool isRequired,
  List<String> startingOptions = const [],
  String? desc,
}) {
  var value = results[name] as List<String>? ?? [];
  if (!isInteractive) {
    if (value.isEmpty) {
      if (startingOptions.isNotEmpty) {
        return startingOptions;
      } else {
        print('Missing parameter $name is required.');
        exit(1);
      }
    }
  }
  if (value.any((e) => !options.contains(e))) {
    print('Invalid value $value provided. Must be in: $options');
    value = [];
  }
  if (desc != null) {
    stdout.write(ansi.darkGray.wrap('\n$desc\u{1B}[1A\r'));
  }
  value = cbx(message, options, startingOptions);
  if (desc != null) {
    stdout.write('\r\u{1B}[K');
  }
  return value;
}