handle method

Future<bool> handle(
  1. String line,
  2. LocalCommandContext context
)

Handles a local-command line, returning true if a command ran.

Unknown commands write an error via LocalCommandContext.writeLine and still return true (the line was a local command, just not recognised).

Implementation

Future<bool> handle(String line, LocalCommandContext context) async {
  final trimmed = line.trimLeft();
  if (!trimmed.startsWith(':')) return false;
  final parts = trimmed.substring(1).trim().split(RegExp(r'\s+'));
  if (parts.isEmpty || parts.first.isEmpty) return true;
  final command = _byName[parts.first];
  if (command == null) {
    context.writeLine('Unknown command: :${parts.first}');
    return true;
  }
  await command.run(context, parts.sublist(1));
  return true;
}