canonicalCommandPath method

List<String> canonicalCommandPath(
  1. List<String> path
)

Implementation

List<String> canonicalCommandPath(List<String> path) {
  if (path.isEmpty) {
    throw MambaRegistryError('defaultCommandPath must not be empty.');
  }
  var registry = this;
  final canonical = <String>[];
  for (final segment in path) {
    final child = registry.commandRegistries
        .where(
          (candidate) =>
              candidate.name == segment ||
              candidate.commandAliases?.contains(segment) == true,
        )
        .firstOrNull;
    if (child == null) {
      throw MambaRegistryError(
        'Unknown default command segment $segment under ${registry.fullPath.join(' ')}.',
      );
    }
    canonical.add(child.name);
    registry = child;
  }
  if (registry.commandRegistries.isNotEmpty) {
    throw MambaRegistryError(
      'defaultCommandPath must end at an executable command.',
    );
  }
  return List.unmodifiable(canonical);
}