splitWireServeArgs function

WireServeArgs splitWireServeArgs(
  1. List<String> args
)

fa wire-serve [--port N] [--stdio] [--token T] interception (issue #1103): same shape as splitServeA2aArgs — the args parser does not know the wire-serve form, so the bare invocation is detected ONLY in the subcommand position (fa wire-serve ...; the literal word as any other argument — e.g. a prompt — never intercepts, review #1113 r2) and the wire-serve flags are stripped from the list that reaches parseCliArgs. Exactly one transport: --stdio and --port together are a usage error (the card pins a loud startup failure, never a silent fallback); a bad --port value is one too. Repeated flags: last occurrence wins, for both --port and --token (review #1113 r2). Decomposed into one-decision helpers — each stays at cyclomatic 3 or under, the CRAP ratchet floor for covered code.

Implementation

WireServeArgs splitWireServeArgs(List<String> args) {
  final isWireServe = args.isNotEmpty && args.first == 'wire-serve';
  if (!isWireServe) {
    return (
      wireServe: false,
      stdio: false,
      port: null,
      token: null,
      cliArgs: args,
    );
  }
  final stdio = _hasStandaloneFlag(args, '--stdio');
  final port = _readPort(args);
  final token = _readToken(args);
  _checkTransportExclusivity(stdio, port);
  return (
    wireServe: true,
    stdio: stdio,
    port: port,
    token: token,
    cliArgs: _keepCliArgs(args),
  );
}