reduceHandlers method

List<(String, Function)> reduceHandlers(
  1. String commandName
)

Implementation

List<(String, Function handler)> reduceHandlers(String commandName) {
  if (subCommands.isEmpty && groups.isEmpty) {
    return [('$name', _handle!)];
  }

  final List<(String, Function handler)> handlers = [];

  for (final subCommand in subCommands) {
    if (subCommand.handle case null) {
      throw MissingMethodException(
          'Command "$commandName.${subCommand.name}" has no handler');
    }

    handlers.add(('$name.${subCommand.name}', subCommand.handle!));
  }

  for (final group in groups) {
    for (final subCommand in group.commands) {
      handlers.add(
          ('$name.${group.name}.${subCommand.name}', subCommand.handle!));
    }
  }

  return handlers;
}