runChildCommand method

FutureOr<String?> runChildCommand(
  1. List<String> path,
  2. ParsedInputs inputs,
  3. List<String> args
)

Implementation

FutureOr<String?> runChildCommand(
  List<String> path,
  ParsedInputs inputs,
  List<String> args,
) async {
  if (path.isEmpty) {
    throw MambaException('A default path under $name must name a command.');
  }
  Command? current;
  List<Command>? children = commands;
  for (final part in path) {
    current = children
        ?.where(
          (candidate) =>
              candidate.name == part ||
              candidate.aliases?.contains(part) == true,
        )
        .firstOrNull;
    if (current == null) {
      // A [MambaCommandNotFoundException] rather than a bare
      // [MambaException]: it is the only rejection in the framework that has
      // to say which commands were on offer, and the executor reports the
      // same failure with the same type.
      throw MambaCommandNotFoundException(part, [
        name,
        ...path.take(path.indexOf(part)),
      ], children?.map((candidate) => candidate.name).toList() ?? const []);
    }
    children = current is GroupCommand ? current.commands : null;
  }
  return current!.run(inputs, args);
}