splitServeA2aArgs function

({List<String> cliArgs, bool serveA2a, bool serveBridge}) splitServeA2aArgs(
  1. List<String> args
)

fa serve [--a2a|--bridge] [--port N] [--token T] interception: the args parser does not know the serve forms, so args is scanned for the bare serve invocation and the serve-specific flags (and their values) are stripped from the list that reaches parseCliArgs. Exactly one serve form must be selected: serveA2a/serveBridge say which, and the caller fails with the usage line when a serve invocation carries neither, both, or is missing its marker.

Implementation

({bool serveA2a, bool serveBridge, List<String> cliArgs}) splitServeA2aArgs(
  List<String> args,
) {
  final isServe = args.contains('serve');
  final cliArgs = isServe
      ? [
          for (var i = 0; i < args.length; i++)
            if (args[i] != 'serve' &&
                args[i] != '--a2a' &&
                args[i] != '--bridge' &&
                args[i] != '--port' &&
                args[i] != '--token' &&
                (i == 0 ||
                    (args[i - 1] != '--port' && args[i - 1] != '--token')))
              args[i],
        ]
      : args;
  return (
    serveA2a: isServe && args.contains('--a2a'),
    serveBridge: isServe && args.contains('--bridge'),
    cliArgs: cliArgs,
  );
}