fromCommand static method

DartDeclaration fromCommand(
  1. List<Command> commandList,
  2. DartDeclaration self,
  3. {required String key,
  4. dynamic testSubject,
  5. dynamic value}
)

Implementation

static DartDeclaration fromCommand(
  List<Command> commandList,
  DartDeclaration self, {
  required String key,
  dynamic testSubject,
  dynamic value,
}) {
  var newSelf = self;

  for (var command in commandList) {
    if (testSubject is String) {
      if ((command.prefix != null && testSubject.startsWith(command.prefix!))) {
        final commandPrefixMatch = command.prefix != null &&
            command.command != null &&
            testSubject.startsWith(command.prefix! + command.command!);
        final commandMatch = command.command == null || testSubject.startsWith(command.command!);

        if (commandPrefixMatch || commandMatch) {
          final notprefixnull = command.notprefix == null;
          final notprefix = !notprefixnull && !testSubject.startsWith(command.notprefix!);

          if (notprefix || notprefixnull) {
            newSelf = command.callback(self, testSubject, key: key, value: value);
            break;
          }
        }
      }
    }
    if (testSubject.runtimeType == command.type) {
      newSelf = command.callback(self, testSubject, key: key, value: value);
      break;
    }
  }

  return newSelf;
}