splitLiveRunArguments function

({List<String> arguments, String? name, String? stoppedAt}) splitLiveRunArguments(
  1. List<String> arguments
)

Splits metro live:run arguments into the command name and everything/// Splits metro live:run arguments into the command name and everything else, keeping the shared live flags (wherever they appear) in arguments.

name is null when no command name comes before the first argument that isn't a shared live flag; that argument (e.g. --help, or a command's own option) is returned as stoppedAt.

Implementation

({String? name, List<String> arguments, String? stoppedAt})
splitLiveRunArguments(List<String> arguments) {
  const Set<String> flagsWithValues = {'-d', '--device', '--uri', '--timeout'};
  for (int i = 0; i < arguments.length; i++) {
    final String arg = arguments[i];
    if (flagsWithValues.contains(arg)) {
      i++;
      continue;
    }
    if (arg == '--all' ||
        arg == '--json' ||
        arg.startsWith('--device=') ||
        arg.startsWith('--uri=') ||
        arg.startsWith('--timeout=')) {
      continue;
    }
    if (arg.startsWith('-')) {
      return (name: null, arguments: arguments, stoppedAt: arg);
    }
    return (
      name: arg,
      arguments: [...arguments.sublist(0, i), ...arguments.sublist(i + 1)],
      stoppedAt: null,
    );
  }
  return (name: null, arguments: arguments, stoppedAt: null);
}