(
result: Extract<ToolDomainResult, { kind: 'device-list' }>,
)
| 498 | } |
| 499 | |
| 500 | function createDeviceListItems( |
| 501 | result: Extract<ToolDomainResult, { kind: 'device-list' }>, |
| 502 | ): TextRenderableItem[] { |
| 503 | const header = createHeader('List Devices'); |
| 504 | if (result.didError) { |
| 505 | return [header, ...createFailureStatusWithDiagnostics(result, 'Failed to list devices')]; |
| 506 | } |
| 507 | |
| 508 | const groupedByPlatform = new Map<string, typeof result.devices>(); |
| 509 | for (const device of result.devices) { |
| 510 | const platformGroup = groupedByPlatform.get(device.platform) ?? []; |
| 511 | platformGroup.push(device); |
| 512 | groupedByPlatform.set(device.platform, platformGroup); |
| 513 | } |
| 514 | |
| 515 | const platformCounts: Record<string, number> = {}; |
| 516 | let totalCount = 0; |
| 517 | const items: TextRenderableItem[] = [header]; |
| 518 | const sortedPlatforms = [...groupedByPlatform.entries()].sort( |
| 519 | ([left], [right]) => getDevicePlatformInfo(left).order - getDevicePlatformInfo(right).order, |
| 520 | ); |
| 521 | |
| 522 | for (const [platform, devices] of sortedPlatforms) { |
| 523 | const info = getDevicePlatformInfo(platform); |
| 524 | const lines: string[] = ['']; |
| 525 | |
| 526 | for (const device of devices) { |
| 527 | if (lines.length > 1) { |
| 528 | lines.push(''); |
| 529 | } |
| 530 | const marker = device.isAvailable ? '\u2713' : '\u2717'; |
| 531 | lines.push(`${info.emoji} [${marker}] ${device.name}`); |
| 532 | lines.push(` OS: ${device.osVersion}`); |
| 533 | lines.push(` UDID: ${device.deviceId}`); |
| 534 | } |
| 535 | |
| 536 | platformCounts[platform] = devices.length; |
| 537 | totalCount += devices.length; |
| 538 | items.push(createSection(`${info.label}:`, lines)); |
| 539 | } |
| 540 | |
| 541 | const countParts = sortedPlatforms |
| 542 | .map(([platform]) => `${platformCounts[platform]} ${platform}`) |
| 543 | .join(', '); |
| 544 | items.push(createStatus('success', `${totalCount} physical devices discovered (${countParts}).`)); |
| 545 | items.push( |
| 546 | createSection('Hints', [ |
| 547 | 'Use the device ID/UDID from above when required by other tools.', |
| 548 | "Save a default device with session-set-defaults { deviceId: 'DEVICE_UDID' }.", |
| 549 | 'Before running build/run/test/UI automation tools, set the desired device identifier in session defaults.', |
| 550 | ]), |
| 551 | ); |
| 552 | return items; |
| 553 | } |
| 554 | |
| 555 | function createSimulatorListItems( |
| 556 | result: Extract<ToolDomainResult, { kind: 'simulator-list' }>, |
no test coverage detected