Skip to content

Commit

Permalink
cli: add a :port suffix optional for --tunnel option
Browse files Browse the repository at this point in the history
  • Loading branch information
doronz88 committed Jun 21, 2024
1 parent bb80cfb commit f3c0a24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ simplify the work with developer services. You can now try to execute any of the
```shell
# Accessing the DVT services
# The --tunnel option may accept either an empty string, or a UDID for a specific device
# The UDID may be suffixed with :PORT in case tunneld in serving at a non-default port
python3 -m pymobiledevice3 developer dvt ls / --tunnel ''
# Or simply without the `--tunnel` option, assuming the tunneld is running
Expand Down
19 changes: 13 additions & 6 deletions pymobiledevice3/cli/cli_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pymobiledevice3.lockdown import LockdownClient, create_using_usbmux
from pymobiledevice3.osu.os_utils import get_os_utils
from pymobiledevice3.remote.remote_service_discovery import RemoteServiceDiscoveryService
from pymobiledevice3.tunneld import async_get_tunneld_devices
from pymobiledevice3.tunneld import TUNNELD_DEFAULT_ADDRESS, async_get_tunneld_devices
from pymobiledevice3.usbmux import select_devices_by_connection_type

USBMUX_OPTION_HELP = 'usbmuxd listener address (in the form of either /path/to/unix/socket OR HOST:PORT'
Expand All @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs):
if self.mutually_exclusive:
ex_str = ', '.join(self.mutually_exclusive)
kwargs['help'] = help + (
' NOTE: This argument is mutually exclusive with '
'\nNOTE: This argument is mutually exclusive with '
' arguments: [' + ex_str + '].'
)
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -211,11 +211,14 @@ def __init__(self, *args, **kwargs):
self.params[:0] = [
RSDOption(('rsd_service_provider_manually', '--rsd'), type=(str, int), callback=self.rsd,
mutually_exclusive=['rsd_service_provider_using_tunneld'],
help='RSD hostname and port number'),
help='\b\n'
'RSD hostname and port number (as provided by a `start-tunnel` subcommand).'),
RSDOption(('rsd_service_provider_using_tunneld', '--tunnel'), callback=self.tunneld,
mutually_exclusive=['rsd_service_provider_manually'],
help='Either an empty string to force tunneld device selection, or a UDID of a tunneld '
'discovered device')
help='\b\n'
'Either an empty string to force tunneld device selection, or a UDID of a tunneld '
'discovered device.\n'
'The string may be suffixed with :PORT in case tunneld is not serving at the default port.')
]

def rsd(self, ctx, param: str, value: Optional[Tuple[str, int]]) -> Optional[RemoteServiceDiscoveryService]:
Expand All @@ -229,7 +232,11 @@ async def _tunneld(self, udid: Optional[str] = None) -> Optional[RemoteServiceDi
if udid is None:
return

rsds = await async_get_tunneld_devices()
port = TUNNELD_DEFAULT_ADDRESS[1]
if ':' in udid:
udid, port = udid.split(':')

rsds = await async_get_tunneld_devices((TUNNELD_DEFAULT_ADDRESS[0], port))
if len(rsds) == 0:
raise NoDeviceConnectedError()

Expand Down

0 comments on commit f3c0a24

Please sign in to comment.