linkFromCommandLine static method
Pure: the device link a process command line reveals, if any.
Implementation
static Future<AppDeviceLink?> linkFromCommandLine(
String cmd,
List<BootedDevice> booted,
Future<(String?, String?)?> Function(String appPath) readBundle,
) async {
final pathUdid = RegExp(r'CoreSimulator/Devices/([0-9A-Fa-f-]{36})').firstMatch(cmd)?.group(1);
if (pathUdid != null) {
final appMatch = RegExp(r'(\S*/([^/]+)\.app)').firstMatch(cmd);
final info = appMatch != null ? await readBundle(appMatch.group(1)!) : null;
return AppDeviceLink(
deviceId: pathUdid,
appName: appMatch?.group(2),
bundleId: info?.$1,
displayName: info?.$2,
);
}
final flag =
RegExp(r'(?:^|\s)(?:-d|--device-id)[=\s]+("[^"]+"|\S+)').firstMatch(cmd)?.group(1)?.replaceAll('"', '');
if (flag == null) return null;
if (RegExp(r'^[0-9A-Fa-f-]{36}$').hasMatch(flag) || isPhysicalIosUdid(flag)) {
return AppDeviceLink(deviceId: flag);
}
final q = flag.toLowerCase();
for (final d in booted) {
if (d.platform != DevicePlatform.ios) continue;
final n = d.name.toLowerCase();
if (n == q || n.startsWith(q) || d.id.toLowerCase().startsWith(q)) {
return AppDeviceLink(deviceId: d.id);
}
}
return null;
}