parseAndGetEvalsToRun function

List<String> parseAndGetEvalsToRun({
  1. required String? evalIds,
  2. required List<String> availableEvalIds,
})

Resolves which eval IDs to run from evalIds and availableEvalIds.

Returns every available eval ID when evalIds is empty.

Throws an ArgumentError when no IDs in evalIds match available IDs.

Implementation

List<String> parseAndGetEvalsToRun({
  required String? evalIds,
  required List<String> availableEvalIds,
}) {
  if (evalIds == null || evalIds.trim().isEmpty) {
    return List<String>.from(availableEvalIds);
  }

  final Set<String> requested = evalIds
      .split(',')
      .map((String value) => value.trim())
      .where((String value) => value.isNotEmpty)
      .toSet();

  final List<String> selected = availableEvalIds
      .where((String id) => requested.contains(id))
      .toList(growable: false);
  if (selected.isEmpty) {
    throw ArgumentError('No matching eval IDs found in `$evalIds`.');
  }
  return selected;
}