matchShellJobId function

ShellJobIdMatch matchShellJobId(
  1. String requested,
  2. Iterable<String> retainedIds
)

Classifies requested against retainedIds (gh-1438): unique same-n match resolves, 2+ stay ambiguous, none falls back to the closest ids.

Implementation

ShellJobIdMatch matchShellJobId(
  String requested,
  Iterable<String> retainedIds,
) {
  final parts = parseShellJobIdParts(requested);
  // Edge case E3: without the minted shape there is nothing to resolve on.
  if (parts == null) return const ShellJobIdNoMatch([]);
  final sameN = [
    for (final id in retainedIds)
      if (parseShellJobIdParts(id)?.n == parts.n) id,
  ]..sort();
  if (sameN.length == 1) return ShellJobIdUnique(sameN.single);
  if (sameN.length > 1) return ShellJobIdAmbiguous(sameN.take(3).toList());
  return ShellJobIdNoMatch(closestShellJobIds(requested, retainedIds));
}