Handle device-related commands. Returns: True if a device command was handled (should exit), False otherwise.
(args)
| 600 | |
| 601 | |
| 602 | def handle_device_commands(args) -> bool: |
| 603 | """ |
| 604 | Handle device-related commands. |
| 605 | |
| 606 | Returns: |
| 607 | True if a device command was handled (should exit), False otherwise. |
| 608 | """ |
| 609 | device_type = ( |
| 610 | DeviceType.ADB |
| 611 | if args.device_type == "adb" |
| 612 | else (DeviceType.HDC if args.device_type == "hdc" else DeviceType.IOS) |
| 613 | ) |
| 614 | |
| 615 | # Handle iOS-specific commands |
| 616 | if device_type == DeviceType.IOS: |
| 617 | return handle_ios_device_commands(args) |
| 618 | |
| 619 | device_factory = get_device_factory() |
| 620 | ConnectionClass = device_factory.get_connection_class() |
| 621 | conn = ConnectionClass() |
| 622 | |
| 623 | # Handle --list-devices |
| 624 | if args.list_devices: |
| 625 | devices = device_factory.list_devices() |
| 626 | if not devices: |
| 627 | print("No devices connected.") |
| 628 | else: |
| 629 | print("Connected devices:") |
| 630 | print("-" * 60) |
| 631 | for device in devices: |
| 632 | status_icon = "✓" if device.status == "device" else "✗" |
| 633 | conn_type = device.connection_type.value |
| 634 | model_info = f" ({device.model})" if device.model else "" |
| 635 | print( |
| 636 | f" {status_icon} {device.device_id:<30} [{conn_type}]{model_info}" |
| 637 | ) |
| 638 | return True |
| 639 | |
| 640 | # Handle --connect |
| 641 | if args.connect: |
| 642 | print(f"Connecting to {args.connect}...") |
| 643 | success, message = conn.connect(args.connect) |
| 644 | print(f"{'✓' if success else '✗'} {message}") |
| 645 | if success: |
| 646 | # Set as default device |
| 647 | args.device_id = args.connect |
| 648 | return not success # Continue if connection succeeded |
| 649 | |
| 650 | # Handle --disconnect |
| 651 | if args.disconnect: |
| 652 | if args.disconnect == "all": |
| 653 | print("Disconnecting all remote devices...") |
| 654 | success, message = conn.disconnect() |
| 655 | else: |
| 656 | print(f"Disconnecting from {args.disconnect}...") |
| 657 | success, message = conn.disconnect(args.disconnect) |
| 658 | print(f"{'✓' if success else '✗'} {message}") |
| 659 | return True |
no test coverage detected