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 || path.contains(name))
    throw ArgumentError.value(path, 'path');
  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)
      throw MambaException('command not found in $name ${path.join(' ')}');
    children = current is GroupCommand ? current.commands : null;
  }
  return current!.run(inputs, args);
}